Skip to main content

Rng

Trait Rng 

Source
pub trait Rng {
    // Required method
    fn fill<A>(&self, arr: A) -> Option<A>
       where A: AsMut<[u8]>;

    // Provided methods
    fn gen_u64(&self) -> Option<u64> { ... }
    fn gen_u128(&self) -> Option<u128> { ... }
}
Expand description

A non-cryptographic source of randomness.

Required Methods§

Source

fn fill<A>(&self, arr: A) -> Option<A>
where A: AsMut<[u8]>,

Fill a buffer with random data.

This method may return None if the buffer couldn’t be filled with random data for any reason.

The buffer is expected to have a consistent implementation of AsMut that always returns a reference to the same underlying bytes. This isn’t required for safety, but can lead to unexpected results.

Provided Methods§

Source

fn gen_u64(&self) -> Option<u64>

Get a random 64bit number.

Source

fn gen_u128(&self) -> Option<u128>

Get a random 128bit number.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<'a, T> Rng for &'a T
where T: Rng + ?Sized,

Source§

fn fill<A>(&self, arr: A) -> Option<A>
where A: AsMut<[u8]>,

Source§

fn gen_u64(&self) -> Option<u64>

Source§

fn gen_u128(&self) -> Option<u128>

Source§

impl<'a, T> Rng for Arc<T>
where T: Rng + 'a + ?Sized,

Available on crate feature alloc only.
Source§

fn fill<A>(&self, arr: A) -> Option<A>
where A: AsMut<[u8]>,

Source§

fn gen_u64(&self) -> Option<u64>

Source§

fn gen_u128(&self) -> Option<u128>

Source§

impl<'a, T> Rng for Box<T>
where T: Rng + 'a + ?Sized,

Available on crate feature alloc only.
Source§

fn fill<A>(&self, arr: A) -> Option<A>
where A: AsMut<[u8]>,

Source§

fn gen_u64(&self) -> Option<u64>

Source§

fn gen_u128(&self) -> Option<u128>

Source§

impl<'a, T> Rng for Option<T>
where T: Rng,

Source§

fn fill<A>(&self, arr: A) -> Option<A>
where A: AsMut<[u8]>,

Source§

fn gen_u64(&self) -> Option<u64>

Source§

fn gen_u128(&self) -> Option<u128>

Implementors§

Source§

impl Rng for Empty

Source§

impl Rng for RandRng

Source§

impl<'a> Rng for dyn ErasedRng + 'a

Source§

impl<'a> Rng for dyn ErasedRng + Sync + Send + 'a

Source§

impl<T> Rng for AssertInternal<T>
where T: Rng,