模块random


>>> print(random.random())    #random() -> x in the interval [0, 1)
0.9276252205739922

>>> print(random.randint(1,2))    #随机取1-2之间的整数
1

2.随机码

>>> import random
>>> checkcode = ''
>>> for i in range(4):
...     current = random.randrange(0,4)
...     if current != i:
...         temp = chr(random.randint(65,90))
...     else:
...         temp = random.randint(0,9)
...     checkcode += str(temp)
... 
>>> print(checkcode)
UFWZ


你可能感兴趣的:(python,Random)