>>> import random
>>>
>>> # 生成1到50之间随机整数:(包括1和50)
... print(random.randint(1,50))
23
>>>
>>> # 随机选取0到100间的偶数:
... print(random.randrange(0, 101, 2))
88
>>>
>>> # 随机浮点数:
... print(random.random())
0.9256800629300243
>>> print(random.uniform(1, 10))
3.3492680822846754
>>>
>>> # 随机选取字符:
... print(random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()'))
y
>>>
>>> # 随机选取列表的元素:
... print(random.choice(['apple', 'banana', 'orange']))
apple
>>>
>>> # 字符串中随机选取指定数量的字符:
... print(random.sample('zyxwvutsrqponmlkjihgfedcba',5))
['l', 'n', 'y', 'v', 't']
>>>
>>> # 打乱排序
... items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
>>> print(random.shuffle(items))
None