Skip to main content

RandomStream

Trait RandomStream 

Source
pub trait RandomStream {
    // Required method
    fn read(&mut self, dest: &mut [u8]);

    // Provided methods
    fn u64(&mut self) -> u64 { ... }
    fn bool(&mut self) -> bool { ... }
    fn below(&mut self, max: u64) -> u64 { ... }
}
Expand description

Stream of random bytes, and the way that Passgen makes choices with them.

Implementations only provide read. What is read must be a plain stream of bytes: reading two bytes has to give the same as reading one byte twice.

Required Methods§

Source

fn read(&mut self, dest: &mut [u8])

Fills the buffer with random bytes.

Provided Methods§

Source

fn u64(&mut self) -> u64

Returns a random 64 bit number, read as eight bytes in little-endian order.

Source

fn bool(&mut self) -> bool

Returns a random boolean. Reads one byte, and is true if its highest bit is not set.

Source

fn below(&mut self, max: u64) -> u64

Returns a random number that is less than max, with every number being as likely as any other.

Reads 64 bit numbers and masks them with the smallest mask of the form 2ⁿ - 1 that covers max - 1, until one of them is less than max. This also reads a number when max is one. Where there is only one option, generating does not ask for a number.

§Panics

Panics if max is zero, because there is no number to return.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: RandomStream + ?Sized> RandomStream for &mut T

Source§

fn read(&mut self, dest: &mut [u8])

Source§

impl<T: RandomStream + ?Sized> RandomStream for Box<T>

Source§

fn read(&mut self, dest: &mut [u8])

Implementors§