I did this to test the randomness of randint:
>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500
You are generating 4500
random numbers from a range 500 <= x <= 5000
. You then check to see for each number whether it has been generated before. The birthday problem tells us what the probability is for two of those numbers to match given n
tries out of a range d
.
You can also invert the formula to calculate how many numbers you have to generate until the chance of generating a duplicate is more than 50%
. In this case you have a >50%
chance of finding a duplicate number after 79
iterations.