Function malachite_base::vecs::random::random_ordered_unique_vecs
source · pub fn random_ordered_unique_vecs<I: Iterator>(
seed: Seed,
xs_gen: &dyn Fn(Seed) -> I,
mean_length_numerator: u64,
mean_length_denominator: u64
) -> RandomOrderedUniqueVecs<I::Item, GeometricRandomNaturalValues<u64>, I> ⓘwhere
I::Item: Ord,
Expand description
Generates random Vec
s using elements from an iterator, where the Vec
s have no repeated
elements, and the elements are in ascending order.
The lengths of the Vec
s are sampled from a geometric distribution with a specified mean
$m$, equal to mean_length_numerator / mean_length_denominator
. $m$ must be greater than 0.
Strictly speaking, the input iterator must generate infinitely many distinct elements. In
practice it only needs to generate $k$ distinct elements, where $k$ is the largest length
actually sampled from the geometric distribution. For example, if
mean_length_numerator / mean_length_denominator
is significantly lower than 256, then it’s
ok to use random_unsigneds::<u8>
.
$$
P((x_i)_{i=0}^{n-1}) = n!P_g(n)\prod_{i=0}^{n-1}P(x_i),
$$
where $P_g(n)$ is the probability function described in geometric_random_unsigneds
.
xs_gen
must be infinite.
Panics
Panics if mean_length_numerator
or mean_length_denominator
are zero, or, if after being
reduced to lowest terms, their sum is greater than or equal to $2^{64}$.
Examples
use itertools::Itertools;
use malachite_base::num::random::random_primitive_ints;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::vecs::random::random_ordered_unique_vecs;
let xs = random_ordered_unique_vecs(EXAMPLE_SEED, &random_primitive_ints::<u8>, 4, 1);
let values = xs.take(20).collect_vec();
assert_eq!(
values.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[][..],
&[11, 32, 38, 85, 134, 136, 162, 166, 177, 200, 203, 217, 223, 235],
&[30, 90, 218, 234],
&[9, 106, 204, 216],
&[151],
&[],
&[78, 91, 97, 213, 253],
&[39, 191],
&[170, 175, 232, 233],
&[],
&[2, 22, 35, 114, 198, 217],
&[],
&[],
&[17, 25, 32, 65, 79, 114, 121, 144, 148, 173, 222],
&[52, 69, 73, 91, 115, 137, 153, 178],
&[],
&[34, 95, 112],
&[],
&[106, 130, 167, 168, 197],
&[86, 101, 122, 150, 172, 177, 207, 218, 221]
]
);