[issue23974] random.randrange() biased output
Skip Montanaro
report at bugs.python.org
Thu Apr 16 21:24:47 CEST 2015
Skip Montanaro added the comment:
I'm completely unqualified to offer a concrete, expert opinion here, but it seems like defaulting _maxwidth to 1L<<52 should work. I have no idea of the resulting performance implications though.
>>> for bpf in (45, 46, 47, 48, 49, 50, 51, 52, 53):
... print bpf,
... print sum(randrange(2**53 * 2//3, _maxwidth=1L<<bpf) % 2 for i in xrange(1000000)) / 1000000.0,
... print sum(randrange(2**52 * 2//3, _maxwidth=1L<<bpf) % 2 for i in xrange(1000000)) / 1000000.0
...
45 0.499959 0.500144
46 0.501622 0.500371
47 0.500257 0.499692
48 0.499567 0.499942
49 0.499789 0.50028
50 0.499882 0.500488
51 0.500479 0.50006
52 0.500553 0.500234
53 0.33275 0.500296
----------
nosy: +skip.montanaro
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23974>
_______________________________________
More information about the Python-bugs-list
mailing list