My question is: How can I generate non-repetitive random numbers in numpy?
list = np.random.random_integers(20,size=(10))
My question is: How can I generate non-repetitive random numbers in numpy?
list = np.random.random_integers(20,size=(10))
I think
numpy.random.sample
doesn't work right, now. This is my way:If you don't insist on using NumPy, you can use
random.sample()
from the standard library:With NumPy, you will have to use
numpy.random.shuffle()
and slicing:You can get this by sorting as well:
Simply generate an array that contains the required range of numbers, then shuffle them by repeatedly swapping a random one with the 0th element in the array. This produces a random sequence that doesn't contain duplicate values.