mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-24 03:29:28 +01:00
Fixed our lack of raising IndexError on random.choice applied to sequences.
This commit is contained in:
parent
9363489e32
commit
3a408f3dd9
@ -53,11 +53,14 @@ def choice(iterable):
|
|||||||
return _choice(iterable)
|
return _choice(iterable)
|
||||||
else:
|
else:
|
||||||
n = 1
|
n = 1
|
||||||
ret = None
|
m = new.module('') # Guaranteed unique value.
|
||||||
|
ret = m
|
||||||
for x in iterable:
|
for x in iterable:
|
||||||
if random.random() < 1/n:
|
if random.random() < 1/n:
|
||||||
ret = x
|
ret = x
|
||||||
n += 1
|
n += 1
|
||||||
|
if ret is m:
|
||||||
|
raise IndexError
|
||||||
return ret
|
return ret
|
||||||
random.choice = choice
|
random.choice = choice
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user