随机生成验证码

方法一:
#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-8
import random
import string
zimu = string.ascii_letters
shuzi = string.digits
str_source = zimu+ shuzi
print ''.join(random.sample(str_source,4))
posted @ 2017-09-18 09:43  sujc-blogs  阅读(164)  评论(0编辑  收藏  举报