1 from random import randint 2 from random import random 3 from random import uniform 4 from random import choice 5 from random import randrange 6 from random import shuffle 7 8 # 产生10个[-10, 10]的int数值 9 # data = [randint(-10, 10) for i in range(10)] 10 11 # 产生10个[0, 1]的float数值 12 # 保留两位小数 13 # data = [round(random(),2) for i in range(10)] 14 15 # 产生10个[1.1, 3.3]的float数值 16 # 边界可不是整数 17 # data = [round(uniform(1.1, 3.3), 2) for i in range(10)] 18 19 # 从序列中随机生成2个元素 20 # data = [choice('tomorrow') for i in range(2)] 21 22 # 随机生成1到100间隔为2的元素,顺序打乱 23 # data = [randrange(1, 100, 2) for i in range(10)] 24 25 # 将序列元素顺序打乱 26 a = [1,2,3,4] 27 shuffle(a) 28 print(a)