标签:ice 元素 amp div and .sh nbsp shuff pytho
>>> import random
随机生成范围内浮点数
>>> random.uniform(10,20)
16.593660100791066
随机生成范围内整数
>>> random.randint(10,20)
20
>>> random.randint(10,20)
14
随机选取序列中的一个元素
>>> random.choice(‘abcdef‘)
‘f‘
>>> random.choice([‘a‘,‘b‘,‘c‘,‘d‘,‘e‘])
‘e‘
随机选取序列中的多个元素
>>> random.sample(‘abcdefgh‘,3)
[‘f‘, ‘b‘, ‘h‘]
>>> random.sample([1,2,3,4,5,6,7,8,9,10,11],3)
[7, 11, 3]
洗牌,只针对list,因为是对list本身的改变
>>> s = [‘a‘,‘b‘,‘c‘,‘d‘,‘e‘]
>>> random.shuffle([‘a‘,‘b‘,‘c‘,‘d‘,‘e‘])
>>> s
[‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘]
cmiao@huskers.unl.edu
python random
标签:ice 元素 amp div and .sh nbsp shuff pytho
原文地址:http://www.cnblogs.com/freemao/p/7076149.html