import random print(random.random()) # 0-1的随机数 print(random.randint(1,8)) # 1-8的随机整数 print(random.choice(‘hello‘)) # 序列随机选择 # print(random.choice([123, ‘a‘, ‘b‘, ‘v‘])) print(random.sample([‘123‘, ‘a‘, ‘b‘, ‘c‘], 2)) # 序列中随机选择指定个随机元素 print(random.randrange(1,8)) # 1-7的随机整数,不包含8 print(chr(90)) # chr存放所有字符,65-90的数字表示26位字母; # 随机生成字母与数字的验证码 code = ‘‘ for i in range(5): add = random.choice([random.randrange(10), chr(random.randrange(65,91))]) code+=str(add) print(code)
时间: 2024-10-10 08:51:01