码迷,mamicode.com
首页 > 编程语言 > 详细

[ Python - 5 ] 通过random模块生成随机字符串

时间:2017-06-25 10:19:12      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:alt   check   hid   display   src   range   for   python   class   

技术分享
import random
checkcode = ‘‘
for i in range(4):
    if i == random.randint(0,3):
        current = chr(random.randrange(65,90))
        checkcode += str(current)
    else:
        checkcode += str(i)

print(checkcode)
View Code

 

[ Python - 5 ] 通过random模块生成随机字符串

标签:alt   check   hid   display   src   range   for   python   class   

原文地址:http://www.cnblogs.com/hukey/p/7076060.html

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