pub fn random_slice_permutations<T>(
seed: Seed,
xs: &[T],
) -> RandomSlicePermutations<'_, T> ⓘExpand description
Uniformly generates a random permutation of references to a slice.
The iterator cannot outlive the slice. It may be more convenient for the iterator to own the
data, in which case you may use
random_vec_permutations instead.
The output length is infinite.
$P(p) = 1/n!$, where $n$ is xs.len().
§Expected complexity per iteration
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len().
§Examples
use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::slices::random_slice_permutations;
let css: Vec<String> = random_slice_permutations(EXAMPLE_SEED, &['a', 'b', 'c', 'd'])
.take(20)
.map(|ds| ds.into_iter().copied().collect())
.collect();
assert_eq!(
css.iter().map(String::as_str).collect_vec().as_slice(),
[
"dacb", "cbad", "cdab", "cbad", "cdab", "bcda", "bcda", "acbd", "bcda", "dbca", "bdac",
"dbac", "dbca", "bcad", "cadb", "dacb", "acbd", "dbac", "bdca", "abdc"
]
);