Use a boolean instead of hacky reference comparison in utils.iter.choice.

This commit is contained in:
Valentin Lorentz 2012-08-05 09:59:42 +02:00
parent 4ffaff0638
commit 393f78c573

View File

@ -98,13 +98,13 @@ def choice(iterable):
return random.choice(iterable)
else:
n = 1
m = new.module('') # Guaranteed unique value.
ret = m
found = False
for x in iterable:
if random.random() < 1/n:
ret = x
found = True
n += 1
if ret is m:
if not found:
raise IndexError
return ret