random_constructible/
impl_for_optiont.rs

1crate::ix!();
2
3impl<T: RandConstruct> RandConstruct for Option<T> {
4    fn random() -> Self {
5        if rand::random::<f64>() < 0.5 {
6            Some(T::random())
7        } else {
8            None
9        }
10    }
11
12    fn uniform() -> Self {
13        if rand::random::<f64>() < 0.5 {
14            Some(T::uniform())
15        } else {
16            None
17        }
18    }
19
20    fn random_with_rng<R: Rng + ?Sized>(rng: &mut R) -> Self {
21        // Use the provided RNG for the coin flip
22        if rng.gen::<f64>() < 0.5 {
23            Some(T::random_with_rng(rng))
24        } else {
25            None
26        }
27    }
28}