Non-repetitive random number in numpy

numpy.random.Generator.choice offers a replace argument to sample without replacement: from numpy.random import default_rng rng = default_rng() numbers = rng.choice(20, size=10, replace=False) If you’re on a pre-1.17 NumPy, without the Generator API, you can use random.sample() from the standard library: print(random.sample(range(20), 10)) You can also use numpy.random.shuffle() and slicing, but this will be less efficient: a … Read more