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 christian.heimes, gurnec, mark.dickinson, rhettinger, serhiy.storchaka, skip.montanaro
Date 2015-07-02.17:52:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1435859541.69.0.350012216093.issue23974@psf.upfronthosting.co.za>
In-reply-to
Content
There's been no activity on this issue in a few months.... The three options as I see it are:

 1. Fix it for both randrange and SystemRandom.randrange, breaking randrange's implied stability between minor versions.
 2. Fix it only for SystemRandom.randrange.
 3. Close it as wont fix (for performance reasons I'd assume?).

Since I'm in favor of option 2, I've attached a simple patch which implements it. Here are some quick-and-dirty performance numbers showing the decrease in performance (3 tests of the original code followed by 3 of the patched code):

$ python -m timeit -r 10 -s 'import random; s = random.SystemRandom(); r = 2**8' 's.randrange(r)'
10000 loops, best of 10: 22.5 usec per loop
$ python -m timeit -r 10 -s 'import random; s = random.SystemRandom(); r = 2**31' 's.randrange(r)'
10000 loops, best of 10: 22.6 usec per loop
$ python -m timeit -r 10 -s 'import random; s = random.SystemRandom(); r = 2**53 * 2//3' 's.randrange(r)'
10000 loops, best of 10: 22.4 usec per loop

$ python -m timeit -r 10 -s 'import random; s = random.SystemRandom(); r = 2**8' 's.randrange(r)'
10000 loops, best of 10: 23.7 usec per loop
$ python -m timeit -r 10 -s 'import random; s = random.SystemRandom(); r = 2**31' 's.randrange(r)'
10000 loops, best of 10: 46.2 usec per loop
$ python -m timeit -r 10 -s 'import random; s = random.SystemRandom(); r = 2**53 * 2//3' 's.randrange(r)'
10000 loops, best of 10: 34.8 usec per loop

The patch also includes a unit test (with a false negative rate of 1 in 8.5 * 10^-8: http://www.wolframalpha.com/input/?i=probability+of+417+or+fewer+successes+in+1000+trials+with+p%3D0.5).

Any opinions on which of the three options should be taken?
History
Date User Action Args
2015-07-02 17:52:21gurnecsetrecipients: + gurnec, skip.montanaro, rhettinger, mark.dickinson, christian.heimes, serhiy.storchaka
2015-07-02 17:52:21gurnecsetmessageid: <1435859541.69.0.350012216093.issue23974@psf.upfronthosting.co.za>
2015-07-02 17:52:21gurneclinkissue23974 messages
2015-07-02 17:52:21gurneccreate