python小白-day5 random模块

random模块

一、生成随机数

1
2
3
4
import random
print (random.random())
print (random.randint( 1 , 2 ))
print (random.randrange( 1 , 10 ))


二、生成随机验证码

1
2
3
4
5
6
7
8
9
10
import random
cc = ''
for i in range ( 6 ):
     current = random.randint( 0 , 4 )
     if current ! = i:
         tmp = chr (random.randint( 65 , 90 ))
     else :
         tmp = random.randint( 0 , 9 )
     cc + = str (tmp)
print (cc)





来自为知笔记(Wiz)


你可能感兴趣的:(python小白-day5 random模块)