Skip to main content

RandomProvider

Trait RandomProvider 

Source
pub trait RandomProvider {
    // Required methods
    fn gen_bool(&mut self) -> Result<bool, ResponseError>;
    fn gen_i32_range(
        &mut self,
        min: i32,
        max: i32,
    ) -> Result<i32, ResponseError>;
    fn gen_usize_range(
        &mut self,
        min: usize,
        max: usize,
    ) -> Result<usize, ResponseError>;
    fn gen_f64_range(
        &mut self,
        min: f64,
        max: f64,
    ) -> Result<f64, ResponseError>;
    fn gen_alphanumeric_char(&mut self) -> Result<char, ResponseError>;
    fn choose_index(&mut self, len: usize) -> Result<usize, ResponseError>;
    fn ratio(
        &mut self,
        numerator: u32,
        denominator: u32,
    ) -> Result<bool, ResponseError>;
}
Expand description

Abstraction over a source of randomness for response generation.

Implementations are provided for Unstructured (for fuzz testing) and for any type implementing rand::Rng via the RandProvider newtype.

Required Methods§

Source

fn gen_bool(&mut self) -> Result<bool, ResponseError>

Generate a random boolean.

Source

fn gen_i32_range(&mut self, min: i32, max: i32) -> Result<i32, ResponseError>

Generate a random i32 within the inclusive range [min, max].

Source

fn gen_usize_range( &mut self, min: usize, max: usize, ) -> Result<usize, ResponseError>

Generate a random usize within the inclusive range [min, max].

Source

fn gen_f64_range(&mut self, min: f64, max: f64) -> Result<f64, ResponseError>

Generate a random f64 within the inclusive range [min, max].

Source

fn gen_alphanumeric_char(&mut self) -> Result<char, ResponseError>

Generate a random alphanumeric character ([0-9a-zA-Z]).

Source

fn choose_index(&mut self, len: usize) -> Result<usize, ResponseError>

Choose a random index in 0..len. Returns an error if len == 0.

Source

fn ratio( &mut self, numerator: u32, denominator: u32, ) -> Result<bool, ResponseError>

Return true with probability numerator / denominator. Panics if numerator == 0 or numerator > denominator.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§