Trait PRNG

Source
pub trait PRNG: Copy + Clone {
    // Required methods
    fn new(seed: &[u8]) -> Self;
    fn next_u8(&mut self) -> u8;
    fn next_u16(&mut self) -> u16;
    fn next_u64(&mut self) -> u64;
}
Expand description

Trait for a deterministic pseudorandom generator.

The trait PRNG characterizes a stateful object that produces pseudorandom bytes (and larger values) in a cryptographically secure way; the object is created with a source seed, and the output is indistinguishable from uniform randomness up to exhaustive enumeration of the possible values of the seed.

PRNG instances must also implement Copy and Clone so that they may be embedded in clonable structures. This implies that copying a PRNG instance is supposed to clone its internal state, and the copy will output the same values as the original.

Required Methods§

Source

fn new(seed: &[u8]) -> Self

Create a new instance over the provided seed.

Source

fn next_u8(&mut self) -> u8

Get the next byte from the PRNG.

Source

fn next_u16(&mut self) -> u16

Get the 16-bit value from the PRNG.

Source

fn next_u64(&mut self) -> u64

Get the 64-bit value from the PRNG.

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§