Thursday, May 22, 2014

Random Number Generation



You could use random.sample to generate the list with one call:

import random
my_randoms = random.sample(xrange(100), 10)

That generates numbers in the (inclusive) range from 0 to 99. If you want 1 to 100, you could use this (thanks to @martineau for pointing out my convoluted solution):

my_randoms = random.sample(xrange(1, 101), 10)

No comments: