标签:python poi items list ack div 一个 point choice
import random from random import random, uniform, randint, randrange, choice, sample, shuffle list = [‘jack‘, ‘rose‘, ‘tom‘, ‘jerry‘] print(random()) # 随机小数 0.0 <= x < 1.0 print(uniform(1, 10)) # 随机小数 x, 1.0 <= x < 10.0 print(randint(1, 10)) # 随机整数 1 to 10, endpoints included print(randrange(0, 101, 2)) # 随机0-101,步进2,也就是偶数 print(randrange(0, 101, 5)) # 随机0-101,步进5,也就是5的倍数 print(choice(‘abcdefghij‘)) # 随机字符串中的一个字符 items = [1, 2, 3, 4, 5, 6, 7] print(items) shuffle(items) # 重新随机排序 print(items) print(sample([1, 2, 3, 4, 5], 3)) # 随机选3个
标签:python poi items list ack div 一个 point choice
原文地址:http://www.cnblogs.com/jackadam/p/7845883.html