random
-
random.random() #0~1 之间随机取值
-
random.uniform(1,10) #1~10内随机取值
-
random.randint(1,50) #1~50 (闭区间)
-
random.randrange(1,5,2) #步长取值
-
*print(random.choices([1,2,3,4,5,],k=2)) # 选择两个元素,会有重复
-
print(random.sample((1,2,3,4,5),k=2)) # 选择两个元素,不会有重复(除非只有两个)
-
lst = [1,2,3,4,5,6,7,8,9,0] random.shuffle(lst) # 顺序打乱* print(lst)