lmacken / quantumrandom

Tools for utilizing the ANU Quantum Random Number Generator
https://pypi.python.org/pypi/quantumrandom
146 stars 36 forks source link

Change range behavior to conform with random.randint() #25

Open rev138 opened 5 years ago

rev138 commented 5 years ago

The practical behavior of quantumrandom.randint(min, max) is that it returns numbers in the range of min..(max - 1). This means it works like the python built-in range() function, but it deviates from the behavior of random.randint() which I assume this module's method is intended to replicate. You can see this discrepancy in action with the following code snippet:

import quantumrandom, random, time

while True:
    qrand = int(quantumrandom.randint(0,1)) # forcing to int for python3
    rand = random.randint(0,1)
    print(qrand, rand)
    time.sleep(0.1)

qrand will only ever print 0, while rand will print either 0 or 1.

Implementing this PR will probably break existing scripts that use this module, but the confusion between the random and quantumrandom versions of the method will no doubt lead to unintentional errors due to bad assumptions. If the behavior isn't changed, I think the documentation should at least mention this issue explicitly.