@@ -1000,31 +1000,6 @@ which incur interpreter overhead.
10001000 # first_true([a,b], x, f) --> a if f(a) else b if f(b) else x
10011001 return next(filter(pred, iterable), default)
10021002
1003- def random_product(*args, repeat=1):
1004- "Random selection from itertools.product(*args, **kwds)"
1005- pools = [tuple(pool) for pool in args] * repeat
1006- return tuple(map(random.choice, pools))
1007-
1008- def random_permutation(iterable, r=None):
1009- "Random selection from itertools.permutations(iterable, r)"
1010- pool = tuple(iterable)
1011- r = len(pool) if r is None else r
1012- return tuple(random.sample(pool, r))
1013-
1014- def random_combination(iterable, r):
1015- "Random selection from itertools.combinations(iterable, r)"
1016- pool = tuple(iterable)
1017- n = len(pool)
1018- indices = sorted(random.sample(range(n), r))
1019- return tuple(pool[i] for i in indices)
1020-
1021- def random_combination_with_replacement(iterable, r):
1022- "Random selection from itertools.combinations_with_replacement(iterable, r)"
1023- pool = tuple(iterable)
1024- n = len(pool)
1025- indices = sorted(random.choices(range(n), k=r))
1026- return tuple(pool[i] for i in indices)
1027-
10281003 def nth_combination(iterable, r, index):
10291004 "Equivalent to list(combinations(iterable, r))[index]"
10301005 pool = tuple(iterable)
0 commit comments