pub fn random_hash_sets_length_range<I: Iterator>(
seed: Seed,
a: u64,
b: u64,
xs_gen: &dyn Fn(Seed) -> I,
) -> RandomHashSets<I::Item, RandomUnsignedRange<u64>, I> ⓘExpand description
Generates random HashSets with lengths in $[a, b)$, using elements from an iterator.
The lengths of the HashSets are sampled from a uniform distribution on $[a, b)$. $a$ must be
less than $b$.
The input iterator must generate at least $b$ distinct elements.
$$ P((x_i)_{i=0}^{n-1}, a, b) = \frac{n!}{b - a}\prod_{i=0}^{n-1}P(x_i). $$
xs_gen must be infinite.
§Expected complexity per iteration
$T(i) = O(b T^\prime(i))$
$M(i) = O(b M^\prime(i))$
where $T$ is time, $M$ is additional memory, $i$ is the iteration number, $T^\prime$ and
$M^\prime$ are the time and memory functions of the iterators produced by xs_gen, and $b$ is
b.
If xs can repeat values, extra draws are needed to reach the required number of distinct
elements, and an iteration fails to terminate if fewer distinct values are reachable than the
requested length.
§Panics
Panics if $a \geq b$.
§Examples
use itertools::Itertools;
use malachite_base::num::random::random_primitive_ints;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::sets::random::random_hash_sets_length_range;
use maplit::hashset;
let xs = random_hash_sets_length_range(EXAMPLE_SEED, 2, 5, &random_primitive_ints::<u8>);
let values = xs.take(20).collect_vec();
assert_eq!(
values,
&[
hashset! {11, 85, 136},
hashset! {134, 200, 203, 235},
hashset! {38, 223, 235},
hashset! {32, 162, 177, 217},
hashset! {30, 166, 218, 234},
hashset! {9, 90, 106},
hashset! {204, 216},
hashset! {97, 151, 213},
hashset! {78, 253},
hashset! {39, 91, 175, 191},
hashset! {2, 170, 232, 233},
hashset! {22, 35, 217},
hashset! {17, 32, 114, 198},
hashset! {65, 114, 173},
hashset! {25, 121, 173, 222},
hashset! {79, 115, 144, 148},
hashset! {52, 69, 73, 137},
hashset! {91, 153},
hashset! {34, 95, 112, 178},
hashset! {106, 167}
]
);