首页 > 其他 > 详细

生成随机验证码

时间:2018-04-20 21:29:05      阅读:120      评论:0      收藏:0      [点我收藏+]
#coding=utf-8

方法一
import random
checkcode=‘‘
for i in range(4): #0,1,2,3
current=random.randrange(0,4)
if current !=i:
temp=chr(random.randint(65,90)) #65以上是字母,chr()把整数作为参数,返回一个对应的字符
else:
temp=random.randint(0,9)
checkcode +=str(temp)
print checkcode



方法二
import random
checkcode=[]
for i in range(4):
if i==random.randint(1,3):
checkcode.append(str(i))
else:
temp=chr(random.randint(65,90))
checkcode.append(str(temp))
print checkcode
print ‘‘.join(checkcode)

生成随机验证码

原文:https://www.cnblogs.com/hyy0927/p/8893260.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!