码迷,mamicode.com
首页 > 其他好文 > 详细

random模块

时间:2017-08-26 14:23:12      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:orm   ice   log   nbsp   code   form   and   验证码   .sh   

import random
 
print(random.random())#(0,1)----float
 
print(random.randint(1,3))  #[1,3]
 
print(random.randrange(1,3)) #[1,3)
 
print(random.choice([1,23,[4,5]]))#23
 
print(random.sample([1,23,[4,5]],2))#[[4, 5], ‘23‘]
 
print(random.uniform(1,3))#1.927109612082716
 
 
item=[1,3,5,7,9]
random.shuffle(item)
print(item)
import random

def v_code():

    code = ‘‘
    for i in range(5):

        num=random.randint(0,9)
        alf=chr(random.randint(65,90))
        add=random.choice([num,alf])
        code += str(add)
    return code

print(v_code())

验证码

  

 

random模块

标签:orm   ice   log   nbsp   code   form   and   验证码   .sh   

原文地址:http://www.cnblogs.com/freelandun/p/7435130.html

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