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

This is always true.

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.

This is never true, and is always false.

Methods

impl Probability
[src]

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.

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.

Construct a probability that is true half of the times (50/50, 50%).

Get the probability value.

To get the percentage, use percentage.

Get the probability percentage.

To get the probability value, use value.

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.

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 Clone for Probability
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Probability
[src]

Formats the value using the given formatter. Read more

impl HasEntropy for Probability
[src]

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]

Allow easy Probability selection of Always and Never from a boolean.

Performs the conversion.

Auto Trait Implementations

impl Send for Probability

impl Sync for Probability