Function malachite_base::sets::random::random_hash_sets_length_inclusive_range
source · [−]pub fn random_hash_sets_length_inclusive_range<I: Iterator>(
seed: Seed,
a: u64,
b: u64,
xs_gen: &dyn Fn(Seed) -> I
) -> RandomHashSets<I::Item, RandomUnsignedInclusiveRange<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 lengths in $[a, b]$, using elements from an iterator.
The lengths of the HashSet
s are sampled from a uniform distribution on $[a, b)$. $a$ must be
less than or equal to $b$.
The input iterator must generate at least $b$ distinct elements.
$$ P((x_i)_{i=0}^{n-1}, a, b) = \frac{n!}{b - a + 1}\prod_{i=0}^{n-1}P(x_i). $$
xs_gen
must be infinite.
Panics
Panics if $a \geq b$.
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_length_inclusive_range;
fn main() {
let xs = random_hash_sets_length_inclusive_range(
EXAMPLE_SEED,
2,
4,
&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}
]
);
}