I need to generate a big array (or list) with random numbers ( 10⁵ numbers) . I was trying like that:
vet = random.sample(range(10),100000)
But when I try to run :
vet = random.sample(range(10),10000)
File "/usr/lib/python2.7/random.py", line 320, in sample raise ValueError("sample larger than population") ValueError: sample larger than population
Any solution?
tkns
I think you're after something like this:
You can you the numpy function and create an array with N space filled with a random number
numpy.random.rand
You can create matrix of random numbers using the function below and arrays also.
What you want is
From the random module documentation:
so when calling
random.sample(range(10), 100000)
you're trying to extract 100000 unique elements in a sequence of length 10 which obviously can't work.Note that
random.random()
returns a floating value between [0 ; 1)random.randrange([start], stop[, step])
returns a random element from the sequencerange([start], stop[, step])
random.randint(a, b)
returns an integer value in [a ; b]random.sample
, the equalitylen(population) >= k
must hold