[issue24567] random.choice IndexError due to double-rounding
Tim Peters
report at bugs.python.org
Sun Jul 12 21:36:54 CEST 2015
Tim Peters added the comment:
I have a question about this new snippet in choice():
+ if i == n and n > 0:
+ i = n - 1
What's the purpose of the "and n > 0" clause? Without it, if i == n == 0 then i will be set to -1, which is just as good as 0 for the purpose of raising IndexError (seq[any_int] raises IndexError when seq is empty).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24567>
_______________________________________
More information about the Python-bugs-list
mailing list