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§
Sourceconst IS_CRYPTOGRAPHICALLY_SECURE: bool = false
const IS_CRYPTOGRAPHICALLY_SECURE: bool = false
Whether the generator is cryptographically secure.
Required Associated Types§
Required Methods§
Sourcefn from_randomness_source(
source: &mut impl RandomnessSource<TNumber = Self::TNumber>,
) -> Self
fn from_randomness_source( source: &mut impl RandomnessSource<TNumber = Self::TNumber>, ) -> Self
Creates a new PseudoRandomNumberGenerator
seeded from a RandomnessSource
.
Sourcefn next_number(&mut self) -> Self::TNumber
fn next_number(&mut self) -> Self::TNumber
Returns the next random number.
Provided Methods§
Sourcefn fill_bytes(&mut self, bytes: &mut [u8])
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.