python random

 随机数

import  random
print random.random()
print random.randrange(1,10)
print random.randint(1,10)

验证码
import random
checkcode=''
for i in range(1,5):
if i==random.randint(1,4):
  temp=chr(random.randint(65,121))
else:
  temp=random.randint(1,9)
checkcode+=str(temp)
print checkcode
原文地址:https://www.cnblogs.com/yanhongjun/p/5280324.html