Function malachite_base::vecs::random::random_vecs_fixed_length_from_single
source · [−]pub const fn random_vecs_fixed_length_from_single<I: Iterator>(
len: u64,
xs: I
) -> RandomFixedLengthVecsFromSingle<I>ⓘNotable traits for RandomFixedLengthVecsFromSingle<I>impl<I: Iterator> Iterator for RandomFixedLengthVecsFromSingle<I> type Item = Vec<I::Item>;
Expand description
Randomly generates Vec
s of a given length using elements from a single iterator.
The probability of a particular length-$n$ Vec
being generated is the product of the
probabilities of each of its elements.
If len
is 0, the output consists of the empty list, repeated.
xs
must be infinite.
Examples
extern crate itertools;
use itertools::Itertools;
use malachite_base::num::random::random_unsigned_inclusive_range;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::vecs::random::random_vecs_fixed_length_from_single;
let xss = random_vecs_fixed_length_from_single(
2,
random_unsigned_inclusive_range::<u32>(EXAMPLE_SEED, 1, 100),
)
.take(10)
.collect_vec();
assert_eq!(
xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[95, 24],
&[99, 71],
&[93, 53],
&[85, 34],
&[48, 2],
&[55, 11],
&[48, 18],
&[90, 93],
&[67, 93],
&[93, 95]
]
);