import random
1.随机产生0-1的浮点数
>>> random.random()
0.010408299058069503
2.随机1-100整数
>>> random.randint(1..., 100)
19
3.随机选取0到100之间的能被2整除的整数
>>> random.randrange(0, 100, 2)
22
4.随机产生指定区间的浮点数(指定的数可以是小数)
>>> random.uniform...@#$%^&*')
'%'
6.随机选取字符串:
>>> random.choice(['LOL', 'NDF', 'CF'])
'LOL'
7.多个字符中生成指定数量的随机字符
>>> random.sample...('abcdefghijklmnopqrstuvwxyz$', 5)
['w', 'm', 'f', 'y', 'o']
扩展1:sample和range连用, 随机产生一个包含1-10的10个元素的列表...>>> random.sample(range(1,11),10)
[3, 10, 8, 9, 5, 2, 7, 1, 6, 4]
拓展2:多个字符中选取指定数量的字符组成新字符串
>>> '-'.join