import random
#随机整数:
print(random.randint(0,99))
#随机选取0到100间的偶数:
print(random.randrange(0,101,2))
#随机浮点数:
print(random.random())
print(random.uniform(1,10))
#随机字符:
print(random.choice('abcdefg&#%^*f'))
#多个字符中选取特定数量的字符:
print(random.sample('abcdefghij',3)) #['f','h','d']
#随机选取字符串:
print(random.choice(['apple','pear','peach','orange','lemon'])) #apple
#洗牌#
items = [1,2,3,4,5,6,7]
print(items)
random.shuffle(items)
print(items)
Python学习记录W05-06:内置模块详解之Random模块
最新推荐文章于 2021-11-22 11:47:42 发布