Trait GenCore

Source
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§

Source

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§

Source

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§

Source

fn gen_u128(&self) -> u128

Returns a random u128 value.

Source

fn gen_i128(&self) -> i128

Returns a random i128 value.

Source

fn gen_u64(&self) -> u64

Returns a random u64 value.

Source

fn gen_i64(&self) -> i64

Returns a random i64 value.

Source

fn gen_u32(&self) -> u32

Returns a random u32 value.

Source

fn gen_i32(&self) -> i32

Returns a random i32 value.

Source

fn gen_u16(&self) -> u16

Returns a random u16 value.

Source

fn gen_i16(&self) -> i16

Returns a random i16 value.

Source

fn gen_u8(&self) -> u8

Returns a random u8 value.

Source

fn gen_i8(&self) -> i8

Returns a random i8 value.

Source

fn gen_usize(&self) -> usize

Returns a random usize value.

Source

fn gen_isize(&self) -> isize

Returns a random isize value.

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.

Implementations on Foreign Types§

Source§

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

Source§

const GEN_KIND: TurboKind = T::GEN_KIND

Source§

fn gen<const SIZE: usize>(&self) -> [u8; SIZE]

Source§

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

Source§

const GEN_KIND: TurboKind = T::GEN_KIND

Source§

fn gen<const SIZE: usize>(&self) -> [u8; SIZE]

Implementors§

Source§

impl GenCore for Rng

Source§

const GEN_KIND: TurboKind = TurboKind::FAST

Source§

impl<T> GenCore for Box<T>
where T: GenCore + ?Sized,

Source§

const GEN_KIND: TurboKind = T::GEN_KIND