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] >>>  

https://docs.python.org/2/library/random.html#random.sample


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -