pub struct Rng { /* private fields */ }Expand description
Deterministic xorshift64* pseudo-random number generator.
Same seed always yields the same sequence across runs and platforms.
Not cryptographically secure: the full state is recoverable from the output, so never use it for security-sensitive values (tokens, secrets, nonces). It is meant for gameplay - procedural generation, spawn jitter, AI variation - where reproducibility matters and predictability does not.
Implementations§
Source§impl Rng
impl Rng
Sourcepub const DEFAULT_SEED: u64 = 0x4d59_5df4_d0f3_3173
pub const DEFAULT_SEED: u64 = 0x4d59_5df4_d0f3_3173
Fallback state used when a zero seed is supplied.
Sourcepub const fn reseed(&mut self, seed: u64)
pub const fn reseed(&mut self, seed: u64)
Reseeds the generator. A zero seed falls back to Self::DEFAULT_SEED.
Sourcepub fn range_u32(&mut self, range: Range<u32>) -> u32
pub fn range_u32(&mut self, range: Range<u32>) -> u32
Returns a uniform u32 sampled from the half-open range.
§Panics
Panics if range is empty (range.start >= range.end).
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.