码迷,mamicode.com
首页 > 其他好文 > 详细

生成6位的随机验证码

时间:2017-07-03 23:55:39      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:check   验证码   span   生成   pre   for   组成   rand   random   

要求:生成6位的字母和数字组成的随机验证码。

实例1:

 1 import random
 2 identify_code=‘‘
 3 for i in range(1):
 4     for j in range(6):
 5         if i==j:
 6             code=chr(random.randint(65,90))
 7         else:
 8             code=random.randint(0,9)
 9         identify_code+=str(code)
10 
11 print(identify_code)

实例2:

 1 import random
 2 checkcode=‘‘
 3 for i in range(6):
 4     current=random.randrange(0,4)
 5     if current!=i:
 6         temp=chr(random.randint(65,90) or random.randint(97,122))
 7     else:
 8         temp=random.randint(0,9)
 9     checkcode+=str(temp)
10 print(checkcode)

 

生成6位的随机验证码

标签:check   验证码   span   生成   pre   for   组成   rand   random   

原文地址:http://www.cnblogs.com/zoe233/p/7113165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!