Struct SmallRng

struct SmallRng(_)

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 [SeedableRng::from_rng]:
    use rand::SeedableRng;
    use rand::rngs::SmallRng;
    let rng = SmallRng::from_rng(&mut rand::rng());
    # let _: SmallRng = rng;
    
    or [SeedableRng::from_os_rng]:
    # use rand::SeedableRng;
    # use rand::rngs::SmallRng;
    let rng = SmallRng::from_os_rng();
    # let _: SmallRng = 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 generators implements RngCore and thus also [Rng][crate::Rng]. See also the Random Values chapter in the book.

Implementations

impl Clone for SmallRng

fn clone(self: &Self) -> SmallRng

impl Debug for SmallRng

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

impl Eq for SmallRng

impl Freeze for SmallRng

impl PartialEq for SmallRng

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

impl RefUnwindSafe for SmallRng

impl RngCore for SmallRng

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

impl SeedableRng for SmallRng

fn from_seed(seed: <Self as >::Seed) -> Self
fn seed_from_u64(state: u64) -> Self

impl Send for SmallRng

impl StructuralPartialEq for SmallRng

impl Sync for SmallRng

impl Unpin for SmallRng

impl UnsafeUnpin for SmallRng

impl UnwindSafe for SmallRng

impl<R> Rng for SmallRng

impl<R> TryRngCore for SmallRng

fn try_next_u32(self: &mut Self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u64(self: &mut Self) -> Result<u64, <R as TryRngCore>::Error>
fn try_fill_bytes(self: &mut Self, dst: &mut [u8]) -> Result<(), <R as TryRngCore>::Error>

impl<T> Any for SmallRng

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for SmallRng

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for SmallRng

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

impl<T> CloneToUninit for SmallRng

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

impl<T> From for SmallRng

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for SmallRng

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for SmallRng

fn into(self: 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 for SmallRng

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

impl<T, U> TryInto for SmallRng

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

impl<V, T> VZip for SmallRng

fn vzip(self: Self) -> V