首页 > 编程语言 > 详细

python模块-random

时间:2016-06-08 12:08:46      阅读:252      评论:0      收藏:0      [点我收藏+]
print(random.randint(1,10)) 生成随机整数,下限必须小于上限
print(random.randrange(1,10)) 生成随机整数,参数为([start],stop,[step])
random.random()  生成0,1的随机浮点数

随机生成4位验证码:

技术分享
 1 import random
 2 checkcode = ‘‘
 3 for i in range(4):
 4     current =random.randrange(0,4)
 5     if current == 2:
 6         temp = chr(random.randint(65,90)) #大写字母
 7     elif current != 3:
 8         temp = chr(random.randint(97,122)) #小写字母
 9     else:
10         temp = random.randint(0,9)
11     checkcode += str(temp)
12 print(checkcode)
验证码

 

python模块-random

原文:http://www.cnblogs.com/ernest-zhang/p/5569521.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!