Python--random模块
2017-07-28 06:59
357 查看
random: 返回区间[0.0, 1.0)之间的实数
>>> random.random()
0.3096170315326241
getrandbits(n): 返回从0到2^n之间的十进制数。
>>> random.getrandbits(4)
10L
uniform(a , b): 返回区间[a, b]内的一个实数
>>> random.uniform(10,100)
53.10799578599581
randrange([start], stop, [step]) :返回从start到stop区间内的一个随机实数。其中start参数若不选默认为0。
>>> random.randrange(0,10,1)
6
choice(seq) : 返回一个列表元素中的任意一个
>>> random.choice([10,20,30,40])
20
shuffle(seq[ , random]) : 打乱一个序列
>>> list1 = [10,20,30,40]
>>> random.shuffle(list1)
>>> list1
[20, 30, 40, 10]
sample ( seq , n) : 从seq序列中取出n个样本
>>> list1
[20, 30, 40, 10]
>>> random.sample(list1,2)
[20, 30]
>>> random.random()
0.3096170315326241
getrandbits(n): 返回从0到2^n之间的十进制数。
>>> random.getrandbits(4)
10L
uniform(a , b): 返回区间[a, b]内的一个实数
>>> random.uniform(10,100)
53.10799578599581
randrange([start], stop, [step]) :返回从start到stop区间内的一个随机实数。其中start参数若不选默认为0。
>>> random.randrange(0,10,1)
6
choice(seq) : 返回一个列表元素中的任意一个
>>> random.choice([10,20,30,40])
20
shuffle(seq[ , random]) : 打乱一个序列
>>> list1 = [10,20,30,40]
>>> random.shuffle(list1)
>>> list1
[20, 30, 40, 10]
sample ( seq , n) : 从seq序列中取出n个样本
>>> list1
[20, 30, 40, 10]
>>> random.sample(list1,2)
[20, 30]
相关文章推荐
- python的random模块及加权随机算法的python实现方法
- Python random模块(获取随机数)常用方法和使用例子
- Python random模块
- python random模块
- Py修行路 python基础 (二十)模块 time模块,random模块,hashlib模块,OS及sys模块
- 16Python标准系列之random模块
- python random模块(获取随机数)的常用方法及示例
- Python中的random模块
- python3之模块random随机数
- Python模块学习笔记— —random
- python random模块整理
- python标准库random模块
- Python模块random
- python中random模块的randint与numpy.random模块的randint
- python(random模块)取10以内的随机数
- Python中random模块生成随机数详解
- python小白-day5 random模块
- python随机数模块random
- Python random模块
- Python random模块