誰能告訴我,如果這段代碼將在列表中只產生唯一的隨機數字:需要使用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]
>>>
謝謝,明白了 –