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 gurnec
Recipients gurnec, mark.dickinson, rhettinger, serhiy.storchaka, skip.montanaro
Date 2015-04-16.19:40:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429213254.08.0.813100971256.issue23974@psf.upfronthosting.co.za>
In-reply-to
Content
I shouldn't have called this a rounding error issue, that's not really what it is.

A smaller example might help.

If I'm given a random int, x, in the range [0, 12), and asked to produce from it a random int, y, in the range (0,8], I've got (at least?) two choices:

1. y = x If x < 8 Else fail
2. y = f(x), where f maps values from [0, 12) -> (0,8]

The problem with method 2 is you end up with a mapping like this:
0,1  -> 0
2    -> 1
3,4  -> 2
5    -> 3
6,7  -> 4
8    -> 5
9,10 -> 6
11   -> 7

_randbelow() uses method 1 above. _int(self.random() * istart) is more like method 2.

I chose 2^53 * 2/3 just because the bias was easy to demonstrate. There will always be some bias when stop-start % 2^53 != 0, but it might not manifest itself as easily as checking for evenness.

Personally, I think 2^52 is still way too high as a cutoff point for using the (presumably faster, I didn't timeit) method 2, but I don't claim to be an expert here....
History
Date User Action Args
2015-04-16 19:40:54gurnecsetrecipients: + gurnec, skip.montanaro, rhettinger, mark.dickinson, serhiy.storchaka
2015-04-16 19:40:54gurnecsetmessageid: <1429213254.08.0.813100971256.issue23974@psf.upfronthosting.co.za>
2015-04-16 19:40:54gurneclinkissue23974 messages
2015-04-16 19:40:53gurneccreate