Struct rgsl::types::ran_discrete::RanDiscrete
source · [−]pub struct RanDiscrete { /* private fields */ }
Implementations
sourceimpl RanDiscrete
impl RanDiscrete
sourcepub fn new(P: &[f64]) -> Option<RanDiscrete>
pub fn new(P: &[f64]) -> Option<RanDiscrete>
This function returns a pointer to a structure that contains the lookup table for the discrete random number generator. The array P[] contains the probabilities of the discrete events; these array elements must all be positive, but they needn’t add up to one (so you can think of them more generally as “weights”)—the preprocessor will normalize appropriately. This return value is used as an argument for the gsl_ran_discrete function below.
sourcepub fn discrete(&self, r: &mut Rng) -> usize
pub fn discrete(&self, r: &mut Rng) -> usize
After the new, above, has been called, you use this function to get the discrete random numbers.
sourcepub fn discrete_pdf(&self, k: usize) -> f64
pub fn discrete_pdf(&self, k: usize) -> f64
Returns the probability P[k]
of observing the variable k. Since P[k]
is not
stored as part of the lookup table, it must be recomputed; this computation takes O(K),
so if K is large and you care about the original array P[k]
used to create the lookup
table, then you should just keep this original array P[k]
around.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RanDiscrete
impl !Send for RanDiscrete
impl !Sync for RanDiscrete
impl Unpin for RanDiscrete
impl UnwindSafe for RanDiscrete
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more