use crate::sims_rngs::choices::Choices;
use core::fmt::Debug;
use rand::distributions::{Bernoulli, Distribution};
use rand::{RngCore, SeedableRng};
pub trait SimRng: RngCore + SeedableRng + Debug {
#[inline]
fn gen_bool(&mut self, p: f64) -> bool {
Bernoulli::new(p)
.expect("Failed to create Bernoulli distribution due to invalid probability")
.sample(self)
}
#[inline]
fn gen_bools(&mut self, p: f64, n: usize) -> Vec<bool> {
let bernoulli = Bernoulli::new(p)
.expect("Failed to create Bernoulli distribution due to invalid probability");
(0..n).map(|_| bernoulli.sample(self)).collect()
}
#[inline]
#[allow(clippy::cast_possible_wrap, clippy::as_conversions)]
fn coin_flip(&mut self) -> bool {
(self.next_u32() as i32) < 0
}
#[inline]
fn choose_weighted<'a, T>(&mut self, choices: &'a Choices<T>) -> &'a T {
choices.sample(self)
}
#[inline]
#[must_use]
fn from_entropy() -> Self {
SeedableRng::from_entropy()
}
}