django - need random numbers in list using python code random.sample(range(1, 100), 3) -
can tell me if piece of code produce unique random numbers in list :
random.sample(range(1, 100), 3)
random.sample(population, k)
return k length list of unique elements chosen population sequence. used random sampling without replacement.
to choose sample range of integers, use range() object argument
>>> import random >>> print random.sample(range(1,100),3) [77, 29, 45] >>>
Comments
Post a Comment