python 随机数

来源:互联网 发布:淘宝牙齿美白仪有用吗 编辑:程序博客网 时间:2024/04/28 08:38
#!/usr/bin/python2.6  
# -*- coding: utf-8 -*- 


import random
import string
print "=======12 <= n <= 20"
print random.randint(12, 20)
print "=======12 <= float <= 20"
print random.uniform(10, 20) 
#2代表是2的倍数,也就一定就偶数
print random.randrange(0, 101, 2)
#从预设的字符中随机选择一个
print random.choice('&#%^*')
#从预设的字符中随机选择2个
print random.sample('&#%^*',2)


#选择3个字符后将其连接
print string.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).replace(" ","")


#选择某一个字符串
print random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )






#洗牌
items = [1, 2, 3, 4, 5, 6]
random.shuffle(items)
print items
0 0
原创粉丝点击