pub fn random_hash_sets<I: Iterator>(
seed: Seed,
xs_gen: &dyn Fn(Seed) -> I,
mean_length_numerator: u64,
mean_length_denominator: u64,
) -> RandomHashSets<I::Item, GeometricRandomNaturalValues<u64>, I> ⓘExpand description
Generates random HashSets using elements from an iterator.
The lengths of the HashSets 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.
§Expected complexity per iteration
$T(i) = O(m T^\prime(i))$
$M(i) = O(m 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 xs, and $m$ is mean_length_numerator / mean_length_denominator.
§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::sets::random::random_hash_sets;
use maplit::hashset;
let xs = random_hash_sets(EXAMPLE_SEED, &random_primitive_ints::<u8>, 4, 1);
let values = xs.take(20).collect_vec();
assert_eq!(
values,
&[
hashset! {},
hashset! {11, 32, 38, 85, 134, 136, 162, 166, 177, 200, 203, 217, 223, 235},
hashset! {30, 90, 218, 234},
hashset! {9, 106, 204, 216},
hashset! {151},
hashset! {},
hashset! {78, 91, 97, 213, 253},
hashset! {39, 191},
hashset! {170, 175, 232, 233},
hashset! {},
hashset! {2, 22, 35, 114, 198, 217},
hashset! {},
hashset! {},
hashset! {17, 25, 32, 65, 79, 114, 121, 144, 148, 173, 222},
hashset! {52, 69, 73, 91, 115, 137, 153, 178},
hashset! {},
hashset! {34, 95, 112},
hashset! {},
hashset! {106, 130, 167, 168, 197},
hashset! {86, 101, 122, 150, 172, 177, 207, 218, 221}
]
);