pub trait Rng {
fn next_u32(&mut self) -> u32;
fn next_u64(&mut self) -> u64;
fn fill_u32(&mut self, buffer: &mut [u32]);
fn fill_u64(&mut self, buffer: &mut [u64]);
fn fill_bytes(&mut self, buffer: &mut [u8]);
fn jump(&mut self);
fn next_f32(&mut self) -> f32 { ... }
fn next_f64(&mut self) -> f64 { ... }
}
Expand description
Random number generator interface.
Required Methods
sourcefn fill_u32(&mut self, buffer: &mut [u32])
fn fill_u32(&mut self, buffer: &mut [u32])
Fills the next u32
elements in the sequence.
Implementations are not required to implement this method with next_u32
.
This may produce distinct values compared to filling naively with next_u32
.
Implementations are required to produce the same result regardless of endianness.
sourcefn fill_bytes(&mut self, buffer: &mut [u8])
fn fill_bytes(&mut self, buffer: &mut [u8])
Fills the byte slice with uniform random bytes.
Implementations are required to produce the same result regardless of endianness.
Provided Methods
sourcefn next_f32(&mut self) -> f32
fn next_f32(&mut self) -> f32
Returns a uniform random f32
in the half-open interval [1.0, 2.0)
.
As only 23 bits are necessary to construct a random float in this range, implementations may override this method to provide a more efficient implementation.
The default implementation simply gets its random bits from next_u32
.
sourcefn next_f64(&mut self) -> f64
fn next_f64(&mut self) -> f64
Returns a uniform random f64
in the half-open interval [1.0, 2.0)
.
As only 52 bits are necessary to construct a random double in this range, implementations may override this method to provide a more efficient implementation.
The default implementation simply gets its random bits from next_u64
.