pub struct Random<R = ThreadRng> { /* private fields */ }Expand description
Enhanced random number generator for scientific computing
This is the core random number generator used throughout the SCIRS2 ecosystem. It provides deterministic, high-quality random number generation with support for seeding, thread-local storage, and scientific reproducibility.
Implementations§
Source§impl<R> Random<R>where
R: Rng,
impl<R> Random<R>where
R: Rng,
Sourcepub fn sample<T, D>(&mut self, distribution: D) -> Twhere
D: Distribution<T>,
pub fn sample<T, D>(&mut self, distribution: D) -> Twhere
D: Distribution<T>,
Sample from a distribution
Sourcepub fn gen_range<T, B>(&mut self, range: B) -> Twhere
T: SampleUniform,
B: SampleRange<T>,
pub fn gen_range<T, B>(&mut self, range: B) -> Twhere
T: SampleUniform,
B: SampleRange<T>,
Generate a random value in a range
Sourcepub fn fill<T>(&mut self, slice: &mut [T])where
StandardUniform: Distribution<T>,
pub fn fill<T>(&mut self, slice: &mut [T])where
StandardUniform: Distribution<T>,
Fill a slice with random values
Sourcepub fn sample_vec<T, D>(&mut self, distribution: D, size: usize) -> Vec<T>where
D: Distribution<T> + Copy,
pub fn sample_vec<T, D>(&mut self, distribution: D, size: usize) -> Vec<T>where
D: Distribution<T> + Copy,
Generate a vector of random values
Sourcepub fn sample_array<T, Dim, D>(
&mut self,
shape: Dim,
distribution: D,
) -> ArrayBase<OwnedRepr<T>, Dim>
pub fn sample_array<T, Dim, D>( &mut self, shape: Dim, distribution: D, ) -> ArrayBase<OwnedRepr<T>, Dim>
Generate a random array with specified shape and distribution
Trait Implementations§
Source§impl SeedableRng for Random<StdRng>
impl SeedableRng for Random<StdRng>
Source§type Seed = <StdRng as SeedableRng>::Seed
type Seed = <StdRng as SeedableRng>::Seed
Seed type, which is restricted to types mutably-dereferenceable as
u8
arrays (we recommend [u8; N] for some N). Read moreSource§fn from_seed(seed: <Random<StdRng> as SeedableRng>::Seed) -> Random<StdRng>
fn from_seed(seed: <Random<StdRng> as SeedableRng>::Seed) -> Random<StdRng>
Create a new PRNG using the given seed. Read more
Source§fn from_rng(rng: &mut impl RngCore) -> Self
fn from_rng(rng: &mut impl RngCore) -> Self
Create a new PRNG seeded from an infallible
Rng. Read moreSource§fn try_from_rng<R>(rng: &mut R) -> Result<Self, <R as TryRngCore>::Error>where
R: TryRngCore,
fn try_from_rng<R>(rng: &mut R) -> Result<Self, <R as TryRngCore>::Error>where
R: TryRngCore,
Create a new PRNG seeded from a potentially fallible
Rng. Read moreSource§fn from_os_rng() -> Self
fn from_os_rng() -> Self
Auto Trait Implementations§
impl<R> Freeze for Random<R>where
R: Freeze,
impl<R> RefUnwindSafe for Random<R>where
R: RefUnwindSafe,
impl<R> Send for Random<R>where
R: Send,
impl<R> Sync for Random<R>where
R: Sync,
impl<R> Unpin for Random<R>where
R: Unpin,
impl<R> UnwindSafe for Random<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. 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>,
Sample a new value, using the given distribution. Read more
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
👎Deprecated since 0.9.0: Renamed to
random to avoid conflict with the new gen keyword in Rust 2024.Alias for
Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
👎Deprecated since 0.9.0: Renamed to
random_rangeAlias for
Rng::random_range.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error.
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
Return the next random
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
Return the next random
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
Fill
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
Wrap RNG with the
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
Convert an
RngCore to a RngReadAdapter.