pub struct XorShiftRng { /* private fields */ }
Expand description
An Xorshift random number generator.
The Xorshift1 algorithm is not suitable for cryptographic purposes
but is very fast. If you do not know for sure that it fits your
requirements, use a more secure one such as StdRng
or OsRng
.
When seeded with zero (i.e. XorShiftRng::from_seed(0)
is called), this implementation
actually uses 0xBAD_5EED_0BAD_5EED_0BAD_5EED_0BAD_5EED
for the seed. This arbitrary value is
used because the underlying algorithm can’t escape from an all-zero state, and the function is
infallible so it can’t signal this by returning an error.
Marsaglia, George (July 2003). “Xorshift RNGs”. Journal of Statistical Software. Vol. 8 (Issue 14). ↩
Trait Implementations§
Source§impl Clone for XorShiftRng
impl Clone for XorShiftRng
Source§fn clone(&self) -> XorShiftRng
fn clone(&self) -> XorShiftRng
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for XorShiftRng
impl Debug for XorShiftRng
Source§impl PartialEq for XorShiftRng
impl PartialEq for XorShiftRng
Source§impl RngCore for XorShiftRng
impl RngCore for XorShiftRng
Source§impl SeedableRng for XorShiftRng
impl SeedableRng for XorShiftRng
Source§type Seed = [u8; 16]
type Seed = [u8; 16]
Seed type, which is restricted to types mutably-dereferenceable as
u8
arrays (we recommend [u8; N]
for some N
). Read moreSource§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: TryRngCore>(rng: &mut R) -> Result<Self, R::Error>
fn try_from_rng<R: TryRngCore>(rng: &mut R) -> Result<Self, R::Error>
Create a new PRNG seeded from a potentially fallible
Rng
. Read moreSource§fn seed_from_u64(state: u64) -> Self
fn seed_from_u64(state: u64) -> Self
Create a new PRNG using a
u64
seed. Read moreSource§fn from_os_rng() -> Self
fn from_os_rng() -> Self
impl Eq for XorShiftRng
impl StructuralPartialEq for XorShiftRng
Auto Trait Implementations§
impl Freeze for XorShiftRng
impl RefUnwindSafe for XorShiftRng
impl Send for XorShiftRng
impl Sync for XorShiftRng
impl Unpin for XorShiftRng
impl UnwindSafe for XorShiftRng
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
.