pub fn random_vec_permutations<T: Clone>(
seed: Seed,
xs: Vec<T>,
) -> RandomVecPermutations<T> ⓘExpand description
Uniformly generates a random Vec of values cloned from an original Vec.
The permutations are Vecs of cloned items. It may be more convenient for the iterator to
return references to a slice, in which case you may use
random_slice_permutations instead.
The output length is infinite.
$P(p) = 1/n!$, where $n$ is xs.len().
§Worst-case complexity per iteration
$T(i) = O(\ell)$
$M(i) = O(\ell)$
where $T$ is time, $M$ is additional memory, $i$ is the iteration number, and $\ell$ is
xs.len().
§Examples
use itertools::Itertools;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::vecs::random_vec_permutations;
let css: Vec<String> = random_vec_permutations(EXAMPLE_SEED, vec!['a', 'b', 'c', 'd'])
.take(20)
.map(|ds| ds.into_iter().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"
]
);