random_permutation

iteration_utilities.random_permutation(iterable, r=None)

Random selection from itertools.permutations().

Parameters
iterableiterable

The iterable to permute with itertools.permutations().

rint or None, optional

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

Returns
random_permutationtuple

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)