Skip to main content

Rng

Trait Rng 

Source
pub trait Rng: TryRng<Error = Infallible> {
    // Required methods
    fn next_u32(&mut self) -> u32;
    fn next_u64(&mut self) -> u64;
    fn fill_bytes(&mut self, dst: &mut [u8]);
}
Expand description

Trait for infallible random number generators

Rng is a sub-trait of TryRng for infallible generators.

§Requirements

See TryRng#Requirements which also apply here.

§Usage

The rand crate provides higher level functionality, for example generation of floating-point values, uniform ranged sampling and shuffling sequences. In particular, rand::RngExt is an extension trait over Rng providing many of the methods one might expect to be able to use on an RNG.

§Implementing Rng

Implement TryRng with type Error = core::convert::Infallible.

Required Methods§

Source

fn next_u32(&mut self) -> u32

Return the next random u32.

Source

fn next_u64(&mut self) -> u64

Return the next random u64.

Source

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

Fill dest with random data.

This method should guarantee that dest is entirely filled with new data, and may panic if this is impossible (e.g. reading past the end of a file that is being used as the source of randomness).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<R> Rng for R
where R: TryRng<Error = Infallible> + ?Sized,