Function malachite_base::vecs::random::random_ordered_unique_vecs_min_length
source · [−]pub fn random_ordered_unique_vecs_min_length<I: Iterator>(
seed: Seed,
min_length: u64,
xs_gen: &dyn Fn(Seed) -> I,
mean_length_numerator: u64,
mean_length_denominator: u64
) -> RandomOrderedUniqueVecs<I::Item, GeometricRandomNaturalValues<u64>, I>ⓘNotable traits for RandomOrderedUniqueVecs<T, I, J>impl<T: Ord, I: Iterator<Item = u64>, J: Iterator<Item = T>> Iterator for RandomOrderedUniqueVecs<T, I, J> type Item = Vec<T>;
where
I::Item: Ord,
Expand description
Generates random Vec
s with a minimum length, using elements from an iterator, where the
Vec
s have no repeated elements, and the elements are in ascending order.
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_unsigned_inclusive_range
, with $a$ equal to min_length
and b
to
u64::MAX
.
xs_gen
must be infinite.
Panics
Panics if mean_length_numerator
or mean_length_denominator
are zero, if their ratio is less
than or equal to min_length
, or if they are too large and manipulating them leads to
arithmetic overflow.
Examples
extern crate itertools;
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_min_length;
let xs = random_ordered_unique_vecs_min_length(
EXAMPLE_SEED,
2,
&random_primitive_ints::<u8>,
6,
1
);
let values = xs.take(20).collect_vec();
assert_eq!(
values.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[11, 85][..],
&[30, 32, 38, 90, 134, 136, 162, 166, 177, 200, 203, 217, 218, 223, 234, 235],
&[9, 106, 151, 204, 213, 216],
&[39, 78, 91, 97, 191, 253],
&[170, 175, 232],
&[2, 233],
&[17, 22, 32, 35, 114, 198, 217],
&[65, 114, 121, 173],
&[25, 79, 144, 148, 173, 222],
&[52, 115],
&[34, 69, 73, 91, 112, 137, 153, 178],
&[95, 106],
&[167, 197],
&[74, 86, 101, 115, 122, 130, 150, 168, 172, 177, 207, 218, 221],
&[9, 48, 52, 109, 123, 133, 159, 201, 247, 250],
&[196, 235],
&[40, 68, 97, 104, 190],
&[7, 216],
&[11, 24, 43, 112, 157, 216, 217],
&[29, 51, 55, 65, 84, 89, 103, 135, 191, 206, 211]
]
);