发布时间:2019-07-06 10:47:13编辑:auto阅读(1894)
python中的随机数
模块:random
函数:
uniform :随机浮点数
>>> print random.uniform(0,100) 37.5204548309
randint :随机整数
>>> print random.randint(0,100) 4
randrange :随机偶数
>>> print random.randrange(0,101,2) 62
random :随机浮点数
>>> print random.random() 0.0472128549103
choice :随机字符
>>> print random.choice('qwertyuiop[];lkjhgfdsazxcvbnm,./') t
sample :多个字符中选取特定数量的字符组成新的字符列表
>>> print random.sample('qwertyuiop[];lkjhgfdsazxcvbnm,./',3) [']', 'c', 'z']
shuffle :洗牌
>>> item = [1,2,3,4,5,6] >>> random.shuffle(item) >>> item [6, 5, 1, 3, 2, 4]
上一篇: 用 Python 实现的线程池
下一篇: python xml.etree.El
48204
46957
37856
35157
29680
26343
25276
20300
19970
18426
54°
6061°
6771°
6257°
6232°
7354°
6180°
6310°
6784°
6790°