Trait bones_asset::bones_utils::GenCore

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§

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§

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§

fn gen_u128(&self) -> u128

Returns a random u128 value.

fn gen_i128(&self) -> i128

Returns a random i128 value.

fn gen_u64(&self) -> u64

Returns a random u64 value.

fn gen_i64(&self) -> i64

Returns a random i64 value.

fn gen_u32(&self) -> u32

Returns a random u32 value.

fn gen_i32(&self) -> i32

Returns a random i32 value.

fn gen_u16(&self) -> u16

Returns a random u16 value.

fn gen_i16(&self) -> i16

Returns a random i16 value.

fn gen_u8(&self) -> u8

Returns a random u8 value.

fn gen_i8(&self) -> i8

Returns a random i8 value.

fn gen_usize(&self) -> usize

Returns a random usize value.

fn gen_isize(&self) -> isize

Returns a random isize value.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

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

§

const GEN_KIND: TurboKind = T::GEN_KIND

§

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

§

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

§

const GEN_KIND: TurboKind = T::GEN_KIND

§

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

§

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

§

const GEN_KIND: TurboKind = T::GEN_KIND

§

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

Implementors§

§

impl GenCore for AtomicRng

§

const GEN_KIND: TurboKind = TurboKind::FAST

§

impl GenCore for Rng

§

const GEN_KIND: TurboKind = TurboKind::FAST