[New-bugs-announce] [issue24546] sequence index bug in random.choice
report at bugs.python.org
Wed Jul 1 18:06:30 CEST 2015
New submission from Serge Anuchin:
It seems there is minor bug in random.choice.
I've got traceback from my server with IndexError from random.choice, but sequence wasn't empty (seq value was: u'\u0411\u0413\u0414\u0416\u0418\u041b\u0426\u042b\u042d\
Maybe I mistaken, but only explanation that I have for this exception is rounding by int() of random value that was very close to 1.
>>> seq = 'test'
>>> seq[int(0.99999999999999995 * len(seq))] # logic from random.choice
IndexError: string index out of range
Is it plausible explanation of exception or I'am wrong?
components: Library (Lib)
nosy: Serge Anuchin, mark.dickinson, rhettinger
title: sequence index bug in random.choice
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce