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§
Provided Methods§
Sourcefn u64(&mut self) -> u64
fn u64(&mut self) -> u64
Returns a random 64 bit number, read as eight bytes in little-endian order.
Sourcefn bool(&mut self) -> bool
fn bool(&mut self) -> bool
Returns a random boolean. Reads one byte, and is true if its highest bit is not set.
Sourcefn below(&mut self, max: u64) -> u64
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".