from random import random
def choose_random_predicate(things, pred):
best_score = -1.0
best_thing = None
for thing in things:
score = random()
if pred(thing) and (score > best_score):
best_thing = thing
best_score = score
return best_thing
is_even = lambda x : x % 2 == 0;
things = list(range(100))
print( choose_random_predicate(things, is_even) )