pub trait GenCore: TurboCore {
const GEN_KIND: TurboKind;
Show 13 methods
// Required method
fn gen<const SIZE: usize>(&self) -> [u8; SIZE];
// Provided methods
fn gen_u128(&self) -> u128 { ... }
fn gen_i128(&self) -> i128 { ... }
fn gen_u64(&self) -> u64 { ... }
fn gen_i64(&self) -> i64 { ... }
fn gen_u32(&self) -> u32 { ... }
fn gen_i32(&self) -> i32 { ... }
fn gen_u16(&self) -> u16 { ... }
fn gen_i16(&self) -> i16 { ... }
fn gen_u8(&self) -> u8 { ... }
fn gen_i8(&self) -> i8 { ... }
fn gen_usize(&self) -> usize { ... }
fn gen_isize(&self) -> isize { ... }
}Expand description
This trait provides the means to easily generate all integer types, provided
the main method underpinning this is implemented: GenCore::gen.
Once implemented, the rest of the trait provides default
implementations for generating all integer types, though it is not
recommended to override these.
The underlying implementation of GenCore::gen does not have to rely on
TurboCore::fill_bytes if the PRNG implementation provides a means to
output directly an array of const size.
Required Associated Constants§
Sourceconst GEN_KIND: TurboKind
const GEN_KIND: TurboKind
Determines the kind of PRNG. TurboKind::FAST RNGs are meant to be very
quick, non-cryptographic PRNGs, while TurboKind::SLOW are slower,
more expensive PRNGs, usually CSPRNGs but not always. Setting this constant
allows for certain algorithms to be toggled for tuning performance of certain
methods.
Required Methods§
Sourcefn gen<const SIZE: usize>(&self) -> [u8; SIZE]
fn gen<const SIZE: usize>(&self) -> [u8; SIZE]
Returns an array of constant SIZE containing random u8 values.
§Example
use turborand::prelude::*;
let rand = Rng::with_seed(Default::default());
let bytes = rand.gen::<10>();
assert_ne!(&bytes, &[0u8; 10], "output should not match a zeroed array");Provided Methods§
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.