# 隨機數(shù)功能
from random import *
# 1.choice(seq)
# seq -- 可以是一個列表,元組或字符串,
# 返回其中的一個隨機項。
c1_1 = choice([1, 2, 3, 4, 5])
c1_2 = choice([1, 2, 3, 4, 5])
c1_3 = choice(range(1, 11))
c1_4 = choice("string")
print(c1_1, c1_2, c1_3, c1_4)
# 2.randint(start, end)
# 返回 [start, end] 之間的一個隨機整數(shù)。包頭又包尾。
c2_1 = randint(-1, 5)
print(c2_1)
# 3. random()
# 返回一個 [0, 1) 的隨機浮點數(shù)
c3_1 = random()
print(c3_1, round(c3_1, 2))
# round() 方法返回浮點數(shù)x的四舍五入值。
# round(x, n)
# print(round(c3_1, 2))
# 4.uniform(a, b)
# 返回 [a, b] 之間的一個隨機浮點數(shù)。
# 注:a和b接受的數(shù)據(jù)大小隨意
print(uniform(10, 20), uniform(20, 10), uniform(30, 30))
# print(uniform(20, 10))
# print(uniform(30, 30))
# 5.randrange(start, end, step)
# 返回[start,end)之間的一個隨機整數(shù)。包頭不包尾。
print(randrange(0, 10, 2))
# 6.sample(seq, number)
# 從 seq 中隨機取出 number 個元素,以列表的形式返回。
# 取出的元素不會重復
print(sample({1, 2, 3, 4, 5}, 3))
# 7.shuffle(lt)
# 將 lt (列表對象) 中的元素打亂。
lt = ['a', 'b', 'c', 'd', 'e', 'f']
shuffle(lt)? # 類似洗牌
print(lt)
# 主要來源:https://urlify.cn/IFB3aq