random module

import random

random.random()  ===> [0.0, 1.0)

random.choice(seq): return an element from the non-empty sequence.

print(random.choice([x for x in range(201) if x%5==0 and x%7==0]))

random.sample(seq/set, k): randomly return a list including k items 

print(random.sample([x for x in range(100, 201)], 5))  ===>[113, 196, 192, 180, 111]

print(random.sample([x for x in range(1,1001) if x%5==0 and x%7==0], 5)) ==> [420, 700, 455, 525, 875]

num = random.uniform(a, b)

a < num < b if a < b

b < num < a if a > b

>>> import random

>>> random.uniform(7, 15)

11.072817090758864

>>> random.uniform(7, 3)

5.372640370008597

>>> int(random.uniform(10, 3))

7

>>>


random.shuffle(seq): the seq will be changed, and return NULL

OR

from random import shuffle

shuffle(list_seq)

the return is Null, but the sequence of list is changed randomly.

shuffle() and random.shuffle()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容