Module learning --random

1 between a random float 0-1

>>> random.random()
0.82544262519395
>>> random.random()
0.11485429482423948
>>>

 

A second random integer between 1-3

>>> random.randint(1,3)
3
>>> random.randint(1,3)
1
>>> random.randint(1,3)
2
>>> 

this is
>>> random.randrange (l, 4)
. 3
>>> random.randrange (l, 4)
. 1
>>> random.randrange (l, 4)
. 3
>>>

 

3 Other

>>> random.choice('hello')
'o'
>>> random.sample('hello',2)
['h', 'l']
>>> random.uniform(0,3)
2.306228935494692
>>> l = [1,2,3,4,5,6,7,8,9]
>>> random.shuffle(l)
>>> l
[9, 5, 2, 8, 7, 4, 6, 3, 1]
>>>

 

4 randomly generated codes

checkcode = ''

for i in range(5):
    current = random.randrange(0,5)
    #字母
    if current == i:
        tmp = CHR (the random.randint (65, 90, ))
     # Digital 
    the else :
        tmp=random.randint(0,9)


    checkcode += str(tmp)

print(checkcode)

 

Guess you like

Origin www.cnblogs.com/goldtree358/p/11713097.html