Skip to content

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

Open
rev138 wants to merge 1 commit intolmacken:developfrom
rev138:randint_range
Open

Change range behavior to conform with random.randint()#25
rev138 wants to merge 1 commit intolmacken:developfrom
rev138:randint_range

Conversation

@rev138
Copy link

@rev138 rev138 commented Jul 3, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant