# 隨機(jī)數(shù)功能
from random import *
# 1.choice(seq)
# seq -- 可以是一個列表,元組或字符串宏侍,
# 返回其中的一個隨機(jī)項(xiàng)。
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] 之間的一個隨機(jī)整數(shù)北戏。包頭又包尾。
c2_1 = randint(-1, 5)
print(c2_1)
# 3. random()
# 返回一個 [0, 1) 的隨機(jī)浮點(diǎn)數(shù)
c3_1 = random()
print(c3_1, round(c3_1, 2))
# round() 方法返回浮點(diǎn)數(shù)x的四舍五入值漫蛔。
# round(x, n)
# print(round(c3_1, 2))
# 4.uniform(a, b)
# 返回 [a, b] 之間的一個隨機(jī)浮點(diǎn)數(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)之間的一個隨機(jī)整數(shù)。包頭不包尾莽龟。
print(randrange(0, 10, 2))
# 6.sample(seq, number)
# 從 seq 中隨機(jī)取出 number 個元素蠕嫁,以列表的形式返回。
# 取出的元素不會重復(fù)
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