您的位置:首页 > 编程语言 > Python开发

python生成随机验证码

2018-03-04 18:48 323 查看
利用python 的random函数生成随机数字

然后将数字转换成字母。
字母的ASCII为65 - 91(大写)

import random

i = random.randrange(65,91)
print(i)
temp = ""
for i in range(6):
num = random.randrange(0, 4)
if num == 3 or num == 1:
rad2 = random.randrange(0, 10)
temp = temp + str(rad2)
else:
rad = random.randrange(65, 91)
c = chr(rad)
temp = temp + c
print(temp)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: