random_constructible/
impl_for_optiont.rs

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