pub struct Rng { /* private fields */ }Expand description
xorshift64 uniform PRNG. Identical seeds produce identical sequences.
Seed 0 is mapped to a non-zero splinter constant to avoid the degenerate
all-zero state.
Implementations§
Source§impl Rng
impl Rng
Sourcepub fn new(seed: u64) -> Self
pub fn new(seed: u64) -> Self
Create a new generator. seed == 0 is remapped to a fixed non-zero
constant (the golden-ratio splinter) so the stream is never stuck at 0.
Sourcepub fn next_range(&mut self, lo: f64, hi: f64) -> f64
pub fn next_range(&mut self, lo: f64, hi: f64) -> f64
Uniform f64 in [lo, hi). Panics if lo >= hi or either bound is
non-finite.
Sourcepub fn next_usize(&mut self, hi: usize) -> usize
pub fn next_usize(&mut self, hi: usize) -> usize
Uniform usize in [0, hi). hi == 0 returns 0 (no-op).
The float-based mapping is retained for compatibility with the
pre-v0.7 model-selection RNG stream; the final clamp protects the
documented bound in the extreme usize case. Prefer next_u64 /
next_unit with integer rejection sampling when unbiased
subsampling matters.
Sourcepub fn next_index(&mut self, hi: usize) -> usize
pub fn next_index(&mut self, hi: usize) -> usize
Uniform usize in [0, hi). hi == 0 returns 0.
Sourcepub fn next_normal(&mut self) -> f64
pub fn next_normal(&mut self) -> f64
Standard normal sample via the Box–Muller transform.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Rng
impl RefUnwindSafe for Rng
impl Send for Rng
impl Sync for Rng
impl Unpin for Rng
impl UnsafeUnpin for Rng
impl UnwindSafe for Rng
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 more