mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-18 16:12:42 +01:00
Use a boolean instead of hacky reference comparison in utils.iter.choice.
This commit is contained in:
parent
4ffaff0638
commit
393f78c573
@ -98,13 +98,13 @@ def choice(iterable):
|
|||||||
return random.choice(iterable)
|
return random.choice(iterable)
|
||||||
else:
|
else:
|
||||||
n = 1
|
n = 1
|
||||||
m = new.module('') # Guaranteed unique value.
|
found = False
|
||||||
ret = m
|
|
||||||
for x in iterable:
|
for x in iterable:
|
||||||
if random.random() < 1/n:
|
if random.random() < 1/n:
|
||||||
ret = x
|
ret = x
|
||||||
|
found = True
|
||||||
n += 1
|
n += 1
|
||||||
if ret is m:
|
if not found:
|
||||||
raise IndexError
|
raise IndexError
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user