Non-repetitive random number in numpy

Academia picture Academia · Dec 14, 2011 · Viewed 79k times · Source

How can I generate non-repetitive random numbers in numpy?

list = np.random.random_integers(20,size=(10))

Answer

strnam picture strnam · Aug 7, 2014

I think numpy.random.sample doesn't work right, now. This is my way:

import numpy as np
np.random.choice(range(20), 10, replace=False)