Struct FastRng

Source
pub struct FastRng { /* private fields */ }
Expand description

A FastRng struct implementing Random. you can initialize it with your own seed using FastRng::seed() Or if the std feature is enabled call FastRng::new() which will seed it with the system time.
For ergonomics and ease of usability the Rng is also provided as a global thread local variable using FastRng::local_rng()

Implementations§

Source§

impl FastRng

Source

pub fn new() -> Self

Creates a new instance of FastRng seeded with the system time.

§Examples
use random_fast_rng::{FastRng, Random};

let mut rng = FastRng::new();
let random_u8 = rng.get_u8();
let arr: [u8; 32] = rng.gen();
Source

pub fn seed(seed: u64, seq: u64) -> Self

A function to manually seed the Rng in no-std cases.

Trait Implementations§

Source§

impl Random for FastRng

Source§

type Error = ()

The Error type, based on the source of randomness, non fallible sources can use Error=()
Source§

fn try_fill_bytes(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>

This is the main method of the trait. You should implement this on your randomness source and will the buffer with random data.
Source§

fn get_u32(&mut self) -> u32

Returns a random u32 number.
Source§

fn fill_bytes(&mut self, buf: &mut [u8])

Uses try_fill_bytes but panics if returns an error. Override if you can gracefully handle errors in the randomness source.
Source§

fn gen<T>(&mut self) -> T
where T: GenerateRand,

Returns a generic random value which implements GenerateRand
Source§

fn get_u8(&mut self) -> u8

Returns a random u8 number.
Source§

fn get_u16(&mut self) -> u16

Returns a random u16 number.
Source§

fn get_u64(&mut self) -> u64

Returns a random u64 number.
Source§

fn get_usize(&mut self) -> usize

Returns a random usize number.
Source§

fn get_u128(&mut self) -> u128

Returns a random u128 number.
Source§

fn get_bool(&mut self) -> bool

Returns a random bool with 50/50 probability.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.