Struct SmallRng

pub struct SmallRng(/* private field */);

A small-state, fast, non-crypto, non-portable PRNG

This is the "standard small" RNG, a generator with the following properties:

The current algorithm is Xoshiro256PlusPlus on 64-bit platforms and Xoshiro128PlusPlus on 32-bit platforms. Both are also implemented by the rand_xoshiro crate.

Seeding (construction)

This generator implements the SeedableRng trait. All methods are suitable for seeding, but note that, even with a fixed seed, output is not portable. Some suggestions:

  1. To automatically seed with a unique seed, use rand::make_rng():
    use rand::rngs::SmallRng;
    let mut rng: SmallRng = rand::make_rng();
    # let _ = rand::Rng::next_u32(&mut rng);
    
  2. To use a deterministic integral seed, use seed_from_u64. This uses a hash function internally to yield a (typically) good seed from any input.
    # use rand::{SeedableRng, rngs::SmallRng};
    let rng = SmallRng::seed_from_u64(1);
    # let _: SmallRng = rng;
    
  3. To seed deterministically from text or other input, use rand_seeder.

See also Seeding RNGs in the book.

Generation

The generator implements Rng and thus also RngExt. See also the Random Values chapter in the book.

Trait Implementations

impl Clone for SmallRng

fn clone(&self) -> SmallRng

impl Debug for SmallRng

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

impl Eq for SmallRng

impl PartialEq for SmallRng

fn eq(&self, other: &SmallRng) -> bool

impl SeedableRng for SmallRng

type Seed = [u8; 32];
fn from_seed(seed: Self::Seed) -> Self
fn seed_from_u64(state: u64) -> Self

impl StructuralPartialEq for SmallRng

impl TryRng for SmallRng

type Error = Infallible;
fn try_next_u32(&mut self) -> Result<u32, Infallible>
fn try_next_u64(&mut self) -> Result<u64, Infallible>
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Infallible>

Auto Trait Implementations

impl Freeze for SmallRng

impl RefUnwindSafe for SmallRng

impl Send for SmallRng

impl Sync for SmallRng

impl Unpin for SmallRng

impl UnsafeUnpin for SmallRng

impl UnwindSafe for SmallRng

Blanket Implementations

impl<R> Rng for SmallRng where R: TryRng<Error = Infallible> + ?Sized,

fn next_u32(&mut self) -> u32
fn next_u64(&mut self) -> u64
fn fill_bytes(&mut self, dst: &mut [u8])

impl<R> RngCore for SmallRng where R: Rng,

impl<R> RngExt for SmallRng where R: Rng + ?Sized,

impl<R> TryRngCore for SmallRng where R: TryRng,

type Error = <R as TryRng>::Error;

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for SmallRng where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for SmallRng

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for SmallRng where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(self) -> U

Calls U::from(self).

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

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

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

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

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