[issue24546] sequence index bug in random.choice

Mark Dickinson report at bugs.python.org
Sun Jul 5 09:18:12 CEST 2015


Mark Dickinson added the comment:

[Tim]
> I suspect, but have not proved, that 1. - 2.**-53 is the only
> random.random() result for which it's possible that double-rounding
> can cause int(i * random.random()) == i.

I'm sure this is true.  Any other random value is at most 1 - 2**-52, and we're always going to have (1 - 2**-52) * i <= next_below(i), (where * represents multiplication in the rationals, with unrounded result), and since next_below(i) is representable both in the extended 64-bit precision and the target 53-bit precision, neither of the roundings will change that inequality.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24546>
_______________________________________


More information about the Python-bugs-list mailing list