Search code examples
pythonrandom

How do I create a list of random numbers without duplicates?


I tried using random.randint(0, 100), but some numbers were the same. Is there a method/module to create a list unique random numbers?


Solution

  • This will return a list of 10 numbers selected from the range 0 to 99, without duplicates.

    import random
    random.sample(range(100), 10)