import random
random.sample(range(10,18),100)
Traceback (most recent call last):
File "<ipython-input-6-f5d60cc38869>", line 1, in <module>
random.sample(range(10,18),100)
File "C:\Users\shamsul\Anaconda3\lib\random.py", line 315, in sample
raise ValueError("Sample larger than population")
ValueError: Sample larger than population
答案 0 :(得分:2)
sample = [random.randrange(10,18) for _ in range(100)]
所以obviously you're going to have repeats,因为样本大于总体,但这将为您提供均匀分布的样本。通常随机样本采用群体的随机子集,因此通过样本的通常定义,您不能拥有比群体大的样本,但是如果您只想要一个均匀分布的列表在一定范围内的随机数,这样就可以了。