I did this to test the randomness of randint:
>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500
As an answer to the answer of Nimbuz:
http://xkcd.com/221/
That's not a repeater. A repeater is when you repeat the same sequence. Not just one number.
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.
Before blaming Python, you should really brush up some probability & statistics theory. Start by reading about the birthday paradox
By the way, the random
module in Python uses the Mersenne twister PRNG, which is considered very good, has an enormous period and was extensively tested. So rest assured you're in good hands.
True randomness definitely includes repetition of values before the whole set of possible values is exhausted. It would not be random otherwise, as you would be able to predict for how long a value would not be repeated.
If you ever rolled dice, you surely got 3 sixes in row quite often...
If you don't want repetative one, generate sequential array and use random.shuffle