Trait PseudoRandomNumberGenerator

Source
pub trait PseudoRandomNumberGenerator {
    type TNumber: Number;

    const IS_CRYPTOGRAPHICALLY_SECURE: bool = false;

    // Required methods
    fn from_randomness_source(
        source: &mut impl RandomnessSource<TNumber = Self::TNumber>,
    ) -> Self;
    fn next_number(&mut self) -> Self::TNumber;

    // Provided method
    fn fill_bytes(&mut self, bytes: &mut [u8]) { ... }
}
Expand description

Simple trait for pseudo random number generators. Types implementing this trait should aim for efficiency above all.

In its essence this is the same as RandomnessSource. We distinguish those types mostly for type safety. These have different purposes.

Provided Associated Constants§

Source

const IS_CRYPTOGRAPHICALLY_SECURE: bool = false

Whether the generator is cryptographically secure.

Required Associated Types§

Required Methods§

Source

fn from_randomness_source( source: &mut impl RandomnessSource<TNumber = Self::TNumber>, ) -> Self

Creates a new PseudoRandomNumberGenerator seeded from a RandomnessSource.

Source

fn next_number(&mut self) -> Self::TNumber

Returns the next random number.

Provided Methods§

Source

fn fill_bytes(&mut self, bytes: &mut [u8])

Fills the given mut slice with random bytes.

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§