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

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

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?

ベストアンサー1

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

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

おすすめ記事