Skip to main content

FastRng

Struct FastRng 

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

A small, fast, non-cryptographic rng with decent statistical properties. Useful for sampling non-security sensitive data or as a deterministic RNG for tests (instead of the SysRng above, which uses the global OS RNG).

The implementation is the same as Xoroshiro64Star.

Implementations§

Source§

impl FastRng

Source

pub fn new() -> Self

Source

pub fn from_sysrng(sys_rng: &mut SysRng) -> Self

Seed a new FastRng from an existing SysRng.

Source

pub fn from_u64(s: u64) -> Self

Trait Implementations§

Source§

impl Debug for FastRng

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FastRng

Source§

fn default() -> Self

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

impl RngCore for FastRng

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

impl SeedableRng for FastRng

Source§

type Seed = [u8; 8]

Seed type, which is restricted to types mutably-dereferenceable as u8 arrays (we recommend [u8; N] for some N). Read more
Source§

fn from_seed(seed: Self::Seed) -> Self

Create a new PRNG using the given seed. Read more
Source§

fn seed_from_u64(state: u64) -> Self

Create a new PRNG using a u64 seed. Read more
Source§

fn from_rng<R>(rng: R) -> Result<Self, Error>
where R: RngCore,

Create a new PRNG seeded from another Rng. 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.