pub struct Probability(/* private fields */);Expand description
A probability represented as a threshold over all possible u64 samples.
Ratios are rounded down to the nearest multiple of 2^-64. Sampling consumes one u64 for
probabilities strictly between zero and one, and consumes no randomness for either endpoint.
Given the same sequence of u64 samples, decisions are identical on every platform.
Implementations§
Source§impl Probability
impl Probability
Sourcepub const fn new(numerator: u64, denominator: u64) -> Option<Self>
pub const fn new(numerator: u64, denominator: u64) -> Option<Self>
Creates a probability from numerator / denominator.
Returns None if the denominator is zero or the numerator exceeds the denominator.
Sourcepub const fn from_f64(value: f64) -> Option<Self>
pub const fn from_f64(value: f64) -> Option<Self>
Creates a probability from an f64 that maps exactly to a 64-bit threshold.
Returns None if value is not finite, is outside [0, 1], or would require rounding.
The exact IEEE-754 value is preserved rather than interpreting its source spelling as a
decimal ratio. Use TryFrom when const evaluation is not required.
Trait Implementations§
Source§impl Clone for Probability
impl Clone for Probability
Source§fn clone(&self) -> Probability
fn clone(&self) -> Probability
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more