Function malachite_base::sets::random::random_hash_sets
source · [−]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>ⓘNotable traits for RandomHashSets<T, I, J>impl<T: Eq + Hash, I: Iterator<Item = u64>, J: Iterator<Item = T>> Iterator for RandomHashSets<T, I, J> type Item = HashSet<T>;
where
I::Item: Eq + Hash,
Expand description
Generates random HashSet
s using elements from an iterator.
The lengths of the HashSet
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
extern crate itertools;
#[macro_use]
extern crate maplit;
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;
fn main() {
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}
]
);
}