random_combination

iteration_utilities.random_combination(iterable, r, replacement=False)

Random selection from itertools.combinations().

Parameters:

iterable : iterable

The iterable to combine with itertools.combinations().

r : int

The number of elements to combine.

replacement : bool, optional

If True then replace already included values (uses itertools.combinations_with_replacement()). Default is False.

Returns:

random_combination : tuple

The randomly chosen combination.

Examples

>>> from iteration_utilities import random_combination
>>> import random
>>> random.seed(5)
>>> random_combination([1,2,3,4,5,6], r=4)
(3, 4, 5, 6)
>>> random.seed(100)
>>> random_combination([1,2,3,4,5,6], r=4, replacement=True)
(2, 2, 4, 4)
>>> random.seed(None)