@Martijn’s solution is enough since you only need to store and shuffle 9000 numbers. If you want numbers from a bigger range and you know (approximately) how many numbers you’ll need, there’s a better way: The function random.sample
will give you numbers in the desired range without
repetition. For example, to get 500 distinct six-digit numbers you’d use:
selected = random.sample(xrange(100000, 1000000), 500)
4
solved Fix a function returning duplicates over time?