在python中用于生成随机数的模块是random,在使用前需要import
import random
print random.random()
# 0.87594424128
import random
print random.uniform(0, 10)
# 5.27462570463
import random
print random.randint(0, 10)
# 8
import random
print random.randrange(0, 20, 2)
# 14
import random
string = 'nice to meet you'
tup = ('nice', 'to', 'meet', 'you')
lst = ['nice', 'to', 'meet', 'you']
dic = {'a': 1, 'b': 2, 'c': 3}
print random.choice(string)
print random.choice(tup)
print random.choice(lst)
'''
c
meet
nice
'''
import random
lst = ['nice', 'to', 'meet', 'you']
random.shuffle(lst)
print lst
# ['you', 'nice', 'to', 'meet']
import random
string = 'nice to meet you'
tup = ('nice', 'to', 'meet', 'you')
lst = ['nice', 'to', 'meet', 'you']
dic = {'a': 1, 'b': 2, 'c': 3}
print random.sample(string, 2)
print random.sample(tup, 2)
print random.sample(lst, 2)
'''
['m', 'i']
['you', 'nice']
['nice', 'to']
'''