pub struct Bernoulli(pub f32);Expand description
A Bernoulli distribution.
Generates boolean values such that:
- P(true) = p
- P(false) = 1 - p.
given a parameter p ∈ [0.0, 1.0].
Tuple Fields§
§0: f32Trait Implementations§
Source§impl Distrib for Bernoulli
impl Distrib for Bernoulli
Source§fn sample(&self, rng: &mut DefaultRng) -> bool
fn sample(&self, rng: &mut DefaultRng) -> bool
Returns booleans sampled from a Bernoulli distribution.
The result is true with probability self.0 and false
with probability 1 - self.0.
§Example
use core::array;
use retrofire_core::math::rand::*;
let rng = &mut DefaultRng::default();
let bern = Bernoulli(0.6); // P(true) = 0.6
let bools = array::from_fn(|_| bern.sample(rng));
assert_eq!(bools, [true, true, false, true, false, true]);impl Copy for Bernoulli
Auto Trait Implementations§
impl Freeze for Bernoulli
impl RefUnwindSafe for Bernoulli
impl Send for Bernoulli
impl Sync for Bernoulli
impl Unpin for Bernoulli
impl UnwindSafe for Bernoulli
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more