# ### random 随机模块 0 <= x < 1 import random #random() 获取随机0-1之间的小数(左闭右开) res = random.random() print(res)
#比较常用的模块有
#randint() 随机产生指定范围内的随机整数 (了解)
res = random.randint(3,8) # 3 4 5 6 7 8
print(res)
随机验证码
# 随机验证码 4位 大写字母 A-Z 小写字母 a-z 数字 0-9
def yanzhengma():
strvar = ‘‘
for i in range(4):
# 大写字母 A-Z
bc = chr(random.randrange(65,91))
# 小写字母 a-z
sc = chr(random.randrange(97,123))
# 数字 0-9
num = str(random.randrange(10))
# 把可能的字符都放在列表里
lst = [bc,sc,num]
# 从中选一个拼接到字符串中
strvar += random.choice(lst)
return strvar
res = yanzhengma()
print(res)
原文:https://www.cnblogs.com/jalen-123/p/13173795.html