python random模块
2016-02-26 17:37
771 查看
random.random()
返回[0,1)之间的浮点数
[b]random.randrange(stop) / random.randrange(start,stop[,step])[/b]
返回[0,stop) / [start,stop)且步长为step的整数
random.randint(start,stop)
返回[start,stop]之间的整数
随机返回一个序列内的值
随机打乱序列的排序
random.uniform(a,b)
返回a和b之间的浮点数,允许a>b
等同于a+(b-a)*random.random()
random.sample(population,k)
population可以是序列、集合
随机返回所有样本里的k个值
返回[0,1)之间的浮点数
[b]random.randrange(stop) / random.randrange(start,stop[,step])[/b]
返回[0,stop) / [start,stop)且步长为step的整数
random.randint(start,stop)
返回[start,stop]之间的整数
random.
choice(seq)
随机返回一个序列内的值
random.
shuffle(seq)
随机打乱序列的排序
import random li=list([i for i in range(1,100)]) random.shuffle(li) print(li)
random.uniform(a,b)
返回a和b之间的浮点数,允许a>b
等同于a+(b-a)*random.random()
random.sample(population,k)
population可以是序列、集合
随机返回所有样本里的k个值
import random li=list([i for i in range(1,100)]) print(random.sample(li, 10))
相关文章推荐
- Python作为移动客户端后台服务器
- mysql的python API
- Python中正则表达式的一些匹配规则
- 利用Python进行文章特征提取(一)
- python mysql
- Python语言特性
- python多线程编程以及join,setDaemon,线程锁的用法
- 廖雪峰python教程
- python终极解决UnicodeEncodeError
- Python学习笔记 - 8.字典(Dict)
- Python学习笔记 - 7.列表(List)
- Python PEP8代码风格
- Python学习笔记 - 6.文件
- Python学习笔记 - 5.字符串(find方法,格式操作符%)
- Python学习笔记 - 4.迭代(while,for)
- python处理txt文件
- 关于python的类方法、实例方法和静态方法区别
- Python学习笔记 - 3.函数
- Python学习笔记 - 2.条件执行
- Python学习笔记 - 1.变量.表达式.语句