pub const fn random_somes<I: Iterator>(xs: I) -> RandomSomes<I>Notable traits for RandomSomes<I>impl<I: Iterator> Iterator for RandomSomes<I>    type Item = Option<I::Item>;
Expand description

Generates random Options except None, with values from a given random iterator.

The values have the same distribution as the values generated by the given iterator: If $Q(x)$ is the probability of $x$ being generated by xs, then

$P(\operatorname{Some}(x)) = Q(x)$.

xs must be infinite.

The output length is infinite.

Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::num::random::random_primitive_ints;
use malachite_base::options::random::random_somes;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::strings::ToDebugString;

assert_eq!(
    prefix_to_string(
        random_somes(random_primitive_ints::<u8>(EXAMPLE_SEED)).map(|x| x.to_debug_string()),
        5
    ),
    "[Some(113), Some(239), Some(69), Some(108), Some(228), ...]",
)