Struct peroxide::macros::matlab_macro::SmallRng
source · pub struct SmallRng(_);
Expand description
An RNG recommended when small state, cheap initialization and good
performance are required. The PRNG algorithm in SmallRng
is chosen to be
efficient on the current platform, without consideration for cryptography
or security. The size of its state is much smaller than for StdRng
.
Reproducibility of output from this generator is however not required, thus
future library versions may use a different internal generator with
different output. Further, this generator may not be portable and can
produce different output depending on the architecture. If you require
reproducible output, use a named RNG, for example XorShiftRng
.
The current algorithm used on all platforms is Xorshift.
Examples
Initializing SmallRng
with a random seed can be done using FromEntropy
:
use rand::FromEntropy;
use rand::rngs::SmallRng;
// Create small, cheap to initialize and fast RNG with a random seed.
// The randomness is supplied by the operating system.
let mut small_rng = SmallRng::from_entropy();
When initializing a lot of SmallRng
’s, using thread_rng
can be more
efficient:
use std::iter;
use rand::{SeedableRng, thread_rng};
use rand::rngs::SmallRng;
// Create a big, expensive to initialize and slower, but unpredictable RNG.
// This is cached and done only once per thread.
let mut thread_rng = thread_rng();
// Create small, cheap to initialize and fast RNGs with random seeds.
// One can generally assume this won't fail.
let rngs: Vec<SmallRng> = iter::repeat(())
.map(|()| SmallRng::from_rng(&mut thread_rng).unwrap())
.take(10)
.collect();
Trait Implementations§
source§impl RngCore for SmallRng
impl RngCore for SmallRng
source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read moresource§impl SeedableRng for SmallRng
impl SeedableRng for SmallRng
§type Seed = <XorShiftRng as SeedableRng>::Seed
type Seed = <XorShiftRng as SeedableRng>::Seed
u8
arrays (we recommend [u8; N]
for some N
). Read moresource§fn from_seed(seed: <SmallRng as SeedableRng>::Seed) -> SmallRng
fn from_seed(seed: <SmallRng as SeedableRng>::Seed) -> SmallRng
source§fn from_rng<R>(rng: R) -> Result<SmallRng, Error>where
R: RngCore,
fn from_rng<R>(rng: R) -> Result<SmallRng, Error>where
R: RngCore,
Rng
. Read moresource§fn seed_from_u64(state: u64) -> Self
fn seed_from_u64(state: u64) -> Self
u64
seed. Read moreAuto Trait Implementations§
impl RefUnwindSafe for SmallRng
impl Send for SmallRng
impl Sync for SmallRng
impl Unpin for SmallRng
impl UnwindSafe for SmallRng
Blanket Implementations§
source§impl<R> FromEntropy for Rwhere
R: SeedableRng,
impl<R> FromEntropy for Rwhere
R: SeedableRng,
source§fn from_entropy() -> R
fn from_entropy() -> R
source§impl<R> Rng for Rwhere
R: RngCore + ?Sized,
impl<R> Rng for Rwhere
R: RngCore + ?Sized,
source§fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
source§fn gen_range<T>(&mut self, low: T, high: T) -> Twhere
T: PartialOrd<T> + SampleUniform,
fn gen_range<T>(&mut self, low: T, high: T) -> Twhere
T: PartialOrd<T> + SampleUniform,
low
, high
), i.e. inclusive of
low
and exclusive of high
. Read moresource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
source§fn sample_iter<T, D, 'a>(&'a mut self, distr: &'a D) -> DistIter<'a, D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D, 'a>(&'a mut self, distr: &'a D) -> DistIter<'a, D, Self, T>where
D: Distribution<T>,
Self: Sized,
source§fn fill<T>(&mut self, dest: &mut T)where
T: AsByteSliceMut + ?Sized,
fn fill<T>(&mut self, dest: &mut T)where
T: AsByteSliceMut + ?Sized,
dest
entirely with random bytes (uniform value distribution),
where dest
is any type supporting AsByteSliceMut
, namely slices
and arrays over primitive integer types (i8
, i16
, u32
, etc.). Read moresource§fn try_fill<T>(&mut self, dest: &mut T) -> Result<(), Error>where
T: AsByteSliceMut + ?Sized,
fn try_fill<T>(&mut self, dest: &mut T) -> Result<(), Error>where
T: AsByteSliceMut + ?Sized,
dest
entirely with random bytes (uniform value distribution),
where dest
is any type supporting AsByteSliceMut
, namely slices
and arrays over primitive integer types (i8
, i16
, u32
, etc.). Read moresource§fn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
p
of being true. Read moresource§fn choose<T, 'a>(&mut self, values: &'a [T]) -> Option<&'a T>
fn choose<T, 'a>(&mut self, values: &'a [T]) -> Option<&'a T>
values
. Read moresource§fn choose_mut<T, 'a>(&mut self, values: &'a mut [T]) -> Option<&'a mut T>
fn choose_mut<T, 'a>(&mut self, values: &'a mut [T]) -> Option<&'a mut T>
values
. Read more