Skip to main content

ThreadFastRng

Struct ThreadFastRng 

Source
pub struct ThreadFastRng(/* private fields */);
Expand description

A thread-local FastRng that is seeded from the global SysRng the first time a thread uses it.

Like FastRng, it’s a small, fast, and non-cryptographic rng with decent statistical properties. Useful for sampling non-security sensitive data.

Shines in multithreaded/async scenarios where don’t want to have to synchronize on a single Mutex<FastRng> or deal with handing out FastRngs to each thread. Instead we let thread-locals handle all the drudgery.

Implementations§

Source§

impl ThreadFastRng

Source

pub fn new() -> Self

Source

pub fn seed(seed: u64)

Set the current thread local rng seed.

Trait Implementations§

Source§

impl Default for ThreadFastRng

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl RngCore for ThreadFastRng

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

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

Fill dest with random data. Read more
Source§

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

Fill dest entirely with random data. Read more

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<F, T, U> Apply<F, U> for T
where F: FnOnce(T) -> U,

Source§

fn apply(self, f: F) -> U

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<R> RngExt for R
where R: RngCore,

Source§

fn gen_bytes<const N: usize>(&mut self) -> [u8; N]

Source§

fn gen_u32(&mut self) -> u32

Source§

fn gen_u64(&mut self) -> u64

Source§

fn gen_u8(&mut self) -> u8

Source§

fn gen_u16(&mut self) -> u16

Source§

fn gen_u128(&mut self) -> u128

Source§

fn gen_bool(&mut self, p: f32) -> bool

Generate true with probability p
Source§

fn gen_boolean(&mut self) -> bool

Flip a coin. Generate true with probability 0.5
Source§

fn gen_f32(&mut self) -> f32

Generates an f32 uniformly distributed in [0, 1).
Source§

fn gen_f64(&mut self) -> f64

Generates an f64 uniformly distributed in [0, 1).
Source§

fn gen_range_i32(&mut self, range: Range<i32>) -> i32

Generates an i32 in [range.start, range.end). Has slight modulo bias for large ranges. See fastmap32.
Source§

fn gen_range_u32(&mut self, range: Range<u32>) -> u32

Generates a u32 in [range.start, range.end). Has slight modulo bias for large ranges. See fastmap32.
Source§

fn gen_range_u64(&mut self, range: Range<u64>) -> u64

Generates a u32 in [range.start, range.end). Has slight modulo bias for large ranges. See fastmap64.
Source§

fn gen_range_usize(&mut self, range: Range<usize>) -> usize

Generates a usize in [range.start, range.end). Has slight modulo bias for large ranges. See fastmap64.
Source§

fn gen_alphanum_bytes<const N: usize>(&mut self) -> [u8; N]

Generate N (nearly uniformly random) alphanumeric (0-9, A-Z, a-z) bytes.
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.