- import random
- #打印一个随机的小数
- print(random.random())
- #打印一个范围的随机数
- print(random.randint(1,5))
- #打印1-4,步长为2的随机数
- print(random.randrange(1,5,2))
- #range(10)中取5个随机数
- print(random.sample(range(10),5))
- checkcode = ""
- for i in range(4):
- if i == random.randrange(0,4):
- temp = chr(random.randint(65,90))
- else:
- temp = random.randint(0,9)
- checkcode += str(temp)
- print(checkcode)
来源: