随机生成验证码

来源:互联网 发布:c语言函数声明与调用 编辑:程序博客网 时间:2024/05/22 05:32

方法一:
#coding: utf-8
import random
import string
checkcode = ”
for i in range(4):
current = random.randrange(0,6)
if current != i:
temp = chr(random.randint(65,90))
else:
temp = random.randint(0,9)
checkcode += str(temp)
print checkcode

方法二

#coding: utf-8import randomimport stringzimu = string.ascii_lettersshuzi = string.digitsstr_source = zimu+ shuziprint ''.join(random.sample(str_source,4))
原创粉丝点击