RandomProvider

Trait RandomProvider 

Source
pub trait RandomProvider: Clone {
    // Required methods
    fn random<T>(&self) -> T
       where StandardUniform: Distribution<T>;
    fn random_range<T>(&self, range: Range<T>) -> T
       where T: SampleUniform + PartialOrd;
    fn random_ratio(&self) -> f64;
    fn random_bool(&self, probability: f64) -> bool;
}
Expand description

Provider trait for random number generation.

This trait abstracts random number generation to enable both deterministic simulation randomness and real random numbers in a unified way. Implementations handle the source of randomness appropriate for their environment.

Required Methods§

Source

fn random<T>(&self) -> T

Generate a random value of type T.

The type T must implement the Standard distribution.

Source

fn random_range<T>(&self, range: Range<T>) -> T

Generate a random value within a specified range.

The range is exclusive of the upper bound (start..end).

Source

fn random_ratio(&self) -> f64

Generate a random f64 between 0.0 and 1.0.

This is a convenience method for generating ratios and percentages.

Source

fn random_bool(&self, probability: f64) -> bool

Generate a random bool with the given probability of being true.

The probability should be between 0.0 and 1.0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§