Struct LinearCongruentialGenerator

Source
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>

Source

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.

Source

pub fn next_value(&mut self) -> ANumber

Returns the next value of the LCG.

Source

pub fn new(initial: ANumber) -> Self

Creates a new LCG with the given initial value. The remaining parameters are carefuly chosen to maximize generator’s quality.

Trait Implementations§

Source§

impl<ANumber: Clone + Number> Clone for LinearCongruentialGenerator<ANumber>

Source§

fn clone(&self) -> LinearCongruentialGenerator<ANumber>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<ANumber: Debug + Number> Debug for LinearCongruentialGenerator<ANumber>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<ANumber: Number> Default for LinearCongruentialGenerator<ANumber>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<ANumber: PartialEq + Number> PartialEq for LinearCongruentialGenerator<ANumber>

Source§

fn eq(&self, other: &LinearCongruentialGenerator<ANumber>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<ANumber: Number> PseudoRandomNumberGenerator for LinearCongruentialGenerator<ANumber>

Source§

type TNumber = ANumber

Source§

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

Creates a new PseudoRandomNumberGenerator seeded from a RandomnessSource.
Source§

const IS_CRYPTOGRAPHICALLY_SECURE: bool = false

Whether the generator is cryptographically secure.
Source§

fn fill_bytes(&mut self, bytes: &mut [u8])

Fills the given mut slice with random bytes.
Source§

impl<ANumber: Eq + Number> Eq for LinearCongruentialGenerator<ANumber>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.