random_permutation

iteration_utilities.random_permutation(iterable, r=None)

Random selection from itertools.permutations().

Parameters:

iterable : iterable

The iterable to permutate with itertools.permutations().

r : int or None, optional

The number of elements to permutate. If None use all elements from the iterable. Default is None.

Returns:

random_permutation : tuple

The randomly chosen permutation.

Examples

One random permutation:

>>> from iteration_utilities import random_permutation
>>> import random
>>> random.seed(20)
>>> random_permutation([1,2,3,4,5,6])
(6, 2, 3, 4, 1, 5)

One random permutation using a subset of the iterable (here 3 elements):

>>> random.seed(5)
>>> random_permutation([1,2,3,4,5,6], r=3)
(5, 3, 6)
>>> random.seed(None)