python中随机函数

 1 #随机函数
 2 import random  #导入random
 3 #随机生字符和数字的验证码
 4 #(65-90)对应的ACIll码对应的字符为a-z
 5 temp=""
 6 for i in range(0,5):#随机生成5位验证码
 7     rad=random.randrange(0,5)
 8     if rad==2 :
 9         s=str(random.randrange(0,9)) #随机生成0-9
10         temp=temp+s
11     else:
12         c=chr(random.randrange(65,91))随机生成字母
13         temp=temp+c
14 print(temp)
15 #输出:A824F 
原文地址:https://www.cnblogs.com/wangbinbin/p/7112862.html