Python: Random
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述:https://docs.python.org/3/library/string.html # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # Datetime : 2023/12/17 18:16 # User : geovindu # Product : PyCharm # Project : pyBaiduAi # File : RandomHelper.py # explain : 学习 import random import string class RandomHelper( object ): """ 随机字符串 """ @staticmethod def getString(length: int ): """ 生成随机的字符串(大小写英文字母、数字组成) :param length :return: """ st = '' randomstr = st.join(random.choice(string.ascii_letters + string.digits) for _ in range (length)) return randomstr @staticmethod def getStringSample(length: int ): """ 生成随机的无重复字符的字符串(大小写英文字母、数字组成) :param length :return: """ st = '' randomstr = st.join(random.sample(string.ascii_letters + string.digits) for _ in range (length)) return randomstr @staticmethod def getCumstmer(length: int ): """ 自定义字符串随机字符串 :param length: 长度 :return: """ st = '' #1 #randomstr =''.join(random.sample(['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'], length)) #2 st = random.sample( 'abcdefghijklmnopqrstuvwxyz!@#$%^&*' ,length) randomstr = ''.join(st) return randomstr @staticmethod def getCumstmerTwo(length: int ): """ 自定义字符串随机字符串 :param length: 长度 :return: """ randomstr = "23456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*+=" st = [] for i in range (length): st.append(random.choice(randomstr)) result = ''.join(st) return result @staticmethod def getCumstmerChinese(length: int ): """ 自定义中文字符串随机字符串 :param length: 长度 :return: """ randomstr = [ '剪' , '石' , '布' , '中' , '国' , '涂' , '聚' , '文' , '学' , '习' ] st = [] for i in range (length): st.append(random.choice(randomstr)) result = ''.join(st) return result |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2022-12-17 CSharp: Chain of Responsibility Pattern in donet core 6
2022-12-17 CSharp: Proxy Pattern in donet.core 6.0
2022-12-17 python: qrcode
2021-12-17 java: MySql Connection using JDK 14.02
2021-12-17 java: Lamdba
2015-12-17 css:Media Queries