pub struct LinearCongruentialGenerator<ANumber: Number> { /* private fields */ }
Expand description
The classical LCG algorithm. In the most general form it does:
X_{n+1} = (X_n * multiplier + increment) % modulus
.
Of course, we use 32
, 64
and 128
as the modulus, and so we completely
skip it and do wrapping arithmetic.
Implementations§
Source§impl<ANumber: Number> LinearCongruentialGenerator<ANumber>
impl<ANumber: Number> LinearCongruentialGenerator<ANumber>
Sourcepub const fn with_params(
multiplier: ANumber,
increment: ANumber,
initial: ANumber,
) -> Self
pub const fn with_params( multiplier: ANumber, increment: ANumber, initial: ANumber, ) -> Self
Creates a new LCG with the given parameters.
§Notes
Both multiplier
and increment
have to be odd. Moreover, increment
should satisfy increment % 4 == 1
condition, otherwise the generator
won’t produce full period.
Sourcepub fn next_value(&mut self) -> ANumber
pub fn next_value(&mut self) -> ANumber
Returns the next value of the LCG.
Trait Implementations§
Source§impl<ANumber: Clone + Number> Clone for LinearCongruentialGenerator<ANumber>
impl<ANumber: Clone + Number> Clone for LinearCongruentialGenerator<ANumber>
Source§fn clone(&self) -> LinearCongruentialGenerator<ANumber>
fn clone(&self) -> LinearCongruentialGenerator<ANumber>
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<ANumber: Number> Default for LinearCongruentialGenerator<ANumber>
impl<ANumber: Number> Default for LinearCongruentialGenerator<ANumber>
Source§impl<ANumber: PartialEq + Number> PartialEq for LinearCongruentialGenerator<ANumber>
impl<ANumber: PartialEq + Number> PartialEq for LinearCongruentialGenerator<ANumber>
Source§fn eq(&self, other: &LinearCongruentialGenerator<ANumber>) -> bool
fn eq(&self, other: &LinearCongruentialGenerator<ANumber>) -> bool
Tests for
self
and other
values to be equal, and is used by ==
.Source§impl<ANumber: Number> PseudoRandomNumberGenerator for LinearCongruentialGenerator<ANumber>
impl<ANumber: Number> PseudoRandomNumberGenerator for LinearCongruentialGenerator<ANumber>
type TNumber = ANumber
Source§fn next_number(&mut self) -> Self::TNumber
fn next_number(&mut self) -> Self::TNumber
Returns the next random number.
Source§fn from_randomness_source(
source: &mut impl RandomnessSource<TNumber = Self::TNumber>,
) -> Self
fn from_randomness_source( source: &mut impl RandomnessSource<TNumber = Self::TNumber>, ) -> Self
Creates a new
PseudoRandomNumberGenerator
seeded from a RandomnessSource
.Source§const IS_CRYPTOGRAPHICALLY_SECURE: bool = false
const IS_CRYPTOGRAPHICALLY_SECURE: bool = false
Whether the generator is cryptographically secure.
Source§fn fill_bytes(&mut self, bytes: &mut [u8])
fn fill_bytes(&mut self, bytes: &mut [u8])
Fills the given mut slice with random bytes.
impl<ANumber: Eq + Number> Eq for LinearCongruentialGenerator<ANumber>
impl<ANumber: Number> StructuralPartialEq for LinearCongruentialGenerator<ANumber>
Auto Trait Implementations§
impl<ANumber> Freeze for LinearCongruentialGenerator<ANumber>where
ANumber: Freeze,
impl<ANumber> RefUnwindSafe for LinearCongruentialGenerator<ANumber>where
ANumber: RefUnwindSafe,
impl<ANumber> Send for LinearCongruentialGenerator<ANumber>where
ANumber: Send,
impl<ANumber> Sync for LinearCongruentialGenerator<ANumber>where
ANumber: Sync,
impl<ANumber> Unpin for LinearCongruentialGenerator<ANumber>where
ANumber: Unpin,
impl<ANumber> UnwindSafe for LinearCongruentialGenerator<ANumber>where
ANumber: 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