Function malachite_base::sets::random::random_hash_sets_min_length
source · [−]pub fn random_hash_sets_min_length<I: Iterator>(
seed: Seed,
min_length: u64,
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 with a minimum length, using elements from an iterator.
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;
#[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_min_length;
fn main() {
let xs = random_hash_sets_min_length(
EXAMPLE_SEED,
2,
&random_primitive_ints::<u8>,
6,
1
);
let values = xs.take(20).collect_vec();
assert_eq!(
values,
&[
hashset!{11, 85},
hashset!{
30, 32, 38, 90, 134, 136, 162, 166, 177, 200, 203, 217, 218, 223, 234, 235
},
hashset!{9, 106, 151, 204, 213, 216},
hashset!{39, 78, 91, 97, 191, 253},
hashset!{170, 175, 232},
hashset!{2, 233},
hashset!{17, 22, 32, 35, 114, 198, 217},
hashset!{65, 114, 121, 173},
hashset!{25, 79, 144, 148, 173, 222},
hashset!{52, 115},
hashset!{34, 69, 73, 91, 112, 137, 153, 178},
hashset!{95, 106},
hashset!{167, 197},
hashset!{74, 86, 101, 115, 122, 130, 150, 168, 172, 177, 207, 218, 221},
hashset!{9, 48, 52, 109, 123, 133, 159, 201, 247, 250},
hashset!{196, 235},
hashset!{40, 68, 97, 104, 190},
hashset!{7, 216},
hashset!{11, 24, 43, 112, 157, 216, 217},
hashset!{29, 51, 55, 65, 84, 89, 103, 135, 191, 206, 211}
]
);
}