Enum chbs::probability::Probability [−][src]
pub enum Probability { Always, Sometimes(f64), Never, }
A probability definition.
This defines what the probability is of something being true.
The function gen_bool
can be used to generate a boolean based on
this probability. Depending on what randomness source is given, it may be cryptographically
secure.
Variants
Always
This is always true.
Sometimes(f64)
This is sometimes true.
If 1.0
it's always true, if 0.0
it is never true, the value may be anywhere in between.
If the value is exactly 0.0
or 1.0
the variants Always
and
Never
should be used instead.
It is therefore recommended to construct this type using the
from
method as this automatically chooses the correct variant.
This value may never be p < 0
or p > 1
, as it will cause panics.
Never
This is never true, and is always false.
Methods
impl Probability
[src]
impl Probability
pub fn from(probability: f64) -> Self
[src]
pub fn from(probability: f64) -> Self
Construct a probability from the given probability value.
If 1.0
it's always true, if 0.0
it is never true.
Values outside this range will be wrapped to their corresponding edge.
pub fn from_percentage(percentage: f64) -> Self
[src]
pub fn from_percentage(percentage: f64) -> Self
Construct a probability from the given percentage.
If 100.0
it's always true, if 0.0
it is never true.
Values outside this range will be wrapped to their corresponding edge.
pub fn half() -> Self
[src]
pub fn half() -> Self
Construct a probability that is true half of the times (50/50, 50%).
pub fn value(&self) -> f64
[src]
pub fn value(&self) -> f64
Get the probability value.
To get the percentage, use percentage
.
pub fn percentage(&self) -> f64
[src]
pub fn percentage(&self) -> f64
Get the probability percentage.
To get the probability value, use value
.
pub fn gen_bool<R: Rng>(self, rng: &mut R) -> bool
[src]
pub fn gen_bool<R: Rng>(self, rng: &mut R) -> bool
Generate a boolean for this probability.
If the given randomness source to rng
is cryptographically secure,
the generated boolean can be considered cryptographically secure as well.
pub fn gen_bool_secure(self) -> bool
[src]
pub fn gen_bool_secure(self) -> bool
Generate a cryptographically secure boolean for this probability.
This method obtains a cryptographically secure randomness source through thread_rng
provided by the rand
crate and generates a boolean through
gen_bool
.
Trait Implementations
impl Copy for Probability
[src]
impl Copy for Probability
impl Clone for Probability
[src]
impl Clone for Probability
fn clone(&self) -> Probability
[src]
fn clone(&self) -> Probability
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Probability
[src]
impl Debug for Probability
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl HasEntropy for Probability
[src]
impl HasEntropy for Probability
fn entropy(&self) -> Entropy
[src]
fn entropy(&self) -> Entropy
Get the entropy value for this whole component. The returned entropy value may be accumulated from various internal entropy sources. Read more
impl From<bool> for Probability
[src]
impl From<bool> for Probability
Allow easy Probability
selection of Always
and Never
from a boolean.
fn from(b: bool) -> Probability
[src]
fn from(b: bool) -> Probability
Performs the conversion.
Auto Trait Implementations
impl Send for Probability
impl Send for Probability
impl Sync for Probability
impl Sync for Probability