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:
- Non-portable: any future library version may replace the algorithm and results may be platform-dependent. (For a small portable generator, use the rand_pcg or rand_xoshiro crate.)
- Non-cryptographic: output is easy to predict (insecure)
- Quality: statistically good quality
- Fast: the RNG is fast for both bulk generation and single values, with consistent cost of method calls
- Fast initialization
- Small state: little memory usage (current state size is 16-32 bytes depending on platform)
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:
- To automatically seed with a unique seed, use [
SeedableRng::from_rng]:
or [use SeedableRng; use SmallRng; let rng = from_rng; # let _: SmallRng = rng;SeedableRng::from_os_rng]:# use SeedableRng; # use SmallRng; let rng = from_os_rng; # let _: SmallRng = rng; - 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 ; let rng = seed_from_u64; # let _: SmallRng = rng; - 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) -> u32fn next_u64(self: &mut Self) -> u64fn fill_bytes(self: &mut Self, dest: &mut [u8])
impl SeedableRng for SmallRng
fn from_seed(seed: <Self as >::Seed) -> Selffn 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) -> TReturns the argument unchanged.
impl<T> ToOwned for SmallRng
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for SmallRng
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses 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