谁能告诉我,如果这段代码将在列表中只产生唯一的随机数字:需要使用Python代码random.sample列表随机数(范围(1,100),3)
random.sample(range(1, 100), 3)
谁能告诉我,如果这段代码将在列表中只产生唯一的随机数字:需要使用Python代码random.sample列表随机数(范围(1,100),3)
random.sample(range(1, 100), 3)
random.sample(人口,K)
Return a k length list of unique elements chosen from the population sequence. Used for random sampling without replacement.
要选择从一个整数范围的样本,使用范围()对象作为参数
>>> import random
>>> print random.sample(range(1,100),3)
[77, 29, 45]
>>>
谢谢,明白了 –