random_product¶
- iteration_utilities.random_product(*iterables, repeat=1)¶
Random selection from
itertools.product()
.- Parameters:
- iterablesiterable
Any amount of iterables from to pass to
itertools.product()
.- repeat
int
, optional The number of random samples. Default is
1
.
- Returns:
- sampletuple
A tuple containing the random samples.
- Raises:
- IndexError
If any iterable is empty.
Examples
Take one random sample:
>>> from iteration_utilities import random_product >>> import random >>> random.seed(70) >>> random_product(['a', 'b'], [1, 2], [0.5, 0.25]) ('a', 2, 0.25)
Or take multiple samples:
>>> random.seed(10) >>> random_product(['a', 'b'], [1, 2], [0.5, 0.25], repeat=5) ('a', 2, 0.25, 'a', 1, 0.25, 'b', 2, 0.5, 'a', 2, 0.25, 'a', 1, 0.25) >>> random.seed(None)