This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jfbu
Recipients jfbu
Date 2020-03-05.20:15:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583439339.66.0.539160874229.issue39867@roundup.psfhosted.org>
In-reply-to
Content
We generate quadruples of random integers using randrange(n) and randrange(m) and count how many times the quadruples are identical, using the same random seed. Of course for nearby n and m (the real life example was with n==95 and m==97) we do expect matches. But we found orders of magnitude more than was expected.

The attached file demonstrates this by comparison with random()*n (with rounding) as alternative method to generate the random integers (we are aware this gives less uniformity for a given range, but these effects are completely negligible in comparison to the effect we test). For the latter the probability of matches is non-vanishing but orders of magnitude smaller than using randrange(n).

Here is an excerpt of our testing result. Each trial uses a random seed (selected via randrange(100000000)). Then 4 random integers in two given ranges are generated and compared. A hit is when all 4 match.

- with randrange():

n = 99, m = 124, 4135 hits among 10000 trials
n = 99, m = 125, 3804 hits among 10000 trials
n = 99, m = 126, 3803 hits among 10000 trials
n = 99, m = 127, 3892 hits among 10000 trials
n = 99, m = 128, 0 hits among 10000 trials
n = 99, m = 129, 0 hits among 10000 trials
n = 99, m = 130, 0 hits among 10000 trials
n = 99, m = 131, 0 hits among 10000 trials

- with random():

n = 99, m = 124, 0 hits among 10000 trials
n = 99, m = 125, 0 hits among 10000 trials
n = 99, m = 126, 0 hits among 10000 trials
n = 99, m = 127, 0 hits among 10000 trials
n = 99, m = 128, 0 hits among 10000 trials
n = 99, m = 129, 0 hits among 10000 trials
n = 99, m = 130, 0 hits among 10000 trials
n = 99, m = 131, 0 hits among 10000 trials

The test file has some hard-coded random seeds for reproductibility.

Although I did only limited testing it is flagrant there is completely abnormal correlation between randrange(n) and randrange(m) when the two integers have the same length in base 2.

Tested with 3.6 and 3.8.
History
Date User Action Args
2020-03-05 20:15:39jfbusetrecipients: + jfbu
2020-03-05 20:15:39jfbusetmessageid: <1583439339.66.0.539160874229.issue39867@roundup.psfhosted.org>
2020-03-05 20:15:39jfbulinkissue39867 messages
2020-03-05 20:15:39jfbucreate