在python中有一个模块random,可以生成随机数,下面就用它做一个简单的随机验证码
import random
check_code = ""
for i in range(6):
current_number = random.randrange(0,6)
if current_number != i:
temp = chr(random.randrange(65,90))
else:
temp = random.randrange(0,9)
check_code = check_code + str(temp)
print check_code
上述简单的几行代码就可以生成随机的字符串。
转载于:https://blog.51cto.com/crazyforever/1733311