Python: Random is barely random at all?

Posted by orokusaki on Stack Overflow See other posts from Stack Overflow or by orokusaki
Published on 2010-01-27T08:50:51Z Indexed on 2010/04/25 21:33 UTC
Read the original article Hit count: 662

I did this to test the randomness of randint:

>>> from random import randint
>>>
>>> uniques = []
>>> for i in range(4500):  # You can see I optimistic.
...     x = randint(500, 5000)
...     if x in uniques:
...         raise Exception('We duped ' + str(x) + ' at iteration number ' + str(i))
...     uniques.append(x)
...
Traceback (most recent call last):
    File "(stdin)", line 4, in (module)
Exception: 'We duped 4061 at iteration number 67

I tried about 10 times more and the best result I got was 121 iterations before a repeater. Is this the best sort of result you can get from the standard library?

© Stack Overflow or respective owner

Related posts about python

Related posts about random-number-generator