python随机生成6位数验证码

时间:2022-08-27 20:02:55

#随机生成6位数验证码

import random
code = []
for i in range(6):
    if i == str(random.randint(1,5)):
        code.append(i)
    else:
       temp =  random.randint(65,90)
       code.append(chr(temp))

print ''.join(code)

###扩充random用法,随机生成树,和程序无关

print random.random()
print random.randint(1,9)
print random.randrange(1,8)