mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +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)
|
||||
else:
|
||||
n = 1
|
||||
ret = None
|
||||
m = new.module('') # Guaranteed unique value.
|
||||
ret = m
|
||||
for x in iterable:
|
||||
if random.random() < 1/n:
|
||||
ret = x
|
||||
n += 1
|
||||
if ret is m:
|
||||
raise IndexError
|
||||
return ret
|
||||
random.choice = choice
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user