import random print(random.random()) # 0.75341741433253 print(random.randint(1, 5)) # [1,5] print(random.uniform(1, 5)) # 随机生成1~5之间的小数 print(random.randrange(1, 10, 2)) # [1,10) print(random.choice([1, "v1", "a1", ["a", "b"]])) # 随机取一个元素 print(random.sample([1,"v1","v2","test",["k1","k2"]],2)) # 随机取两个元素 # 随机验证码 print(chr(69)) print(ord("E")) num = 0 verify_code = "" while num < 4: verify_code += chr(randint(65, 90)) num += 1 # 使用random.random() 生成m~n之间的整数 import random import time def rand(m, n): return int(random.random() * (n - m + 1) + m) while True: time.sleep(0.2) print(rand(1,10))