import random
print(random.random()) # (0, 1)---float 大于0小于1的小数
print(random.randint(1, 3)) # [1, 3] 大于等于1小于等于3之间的整数
print(random.randrange(1, 3)) # [1, 3) 大于等于1小于3之间的整数
print(random.choice([1, '23', [4, 5]])) # 1或'23'或[4, 5]
print(random.sample([1, '23', [4, 5]], 2)) # 列表元素任意2个组合
print(random.uniform(1, 3)) # 大于1小于3的小数
item = [1, 2, 3, 4, 5]
random.shuffle(item) # 打乱列表元素的顺序
print(item)
# 应用:随机验证码
def make_code(size):
res = ''
for i in range(size):
s1 = str(random.randint(0, 9)) # 随机取数字
s2 = chr(random.randint(65, 90)) # 随机取大写字母
res += random.choice(([s1, s2]))
return res
print(make_code(6))