random模块

import random

#随机获取1-9中的任意的整数

res = random.randint(1,9)
print(res)



#默认获取0-1之间任意小数
res = random.random()
print()




#将可迭代中的值进行乱序
list1 =["cn","wh","yjg","zc"]
random.shuffle(list1print(list1)





#随机获取可迭代对象中的某一个值

list1 = ["cn","wh","yjg","zc"]

res = random.choice(list1)
print(res)



举例:
需求是随机验证码
前置技术
chr() 可以将ASCII表中值转换成对应的字符
random.choice









原文地址:https://www.cnblogs.com/medigrat/p/11872918.html