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()
网友评论