pub struct LinearCongruentialGenerator { /* private fields */ }Expand description
Pseudo-random number generator for uniform distribution.
§LaTeX Formula
- N_{i} = (aN_{i-1}+b) mod M
§Links
- Wikipedia: https://en.wikipedia.org/wiki/Linear_congruential_generator
- Original Source: https://archive.org/details/proceedings_of_a_second_symposium_on_large-scale_/mode/2up
§Examples
use ndarray::Array1;
use digifi::utilities::TEST_ACCURACY;
use digifi::random_generators::{RandomGenerator, LinearCongruentialGenerator};
let lcg: LinearCongruentialGenerator = LinearCongruentialGenerator::new(12_345, 1_000_000, 244_944, 1_597, 51_749);
let sample: Array1<f64> = lcg.generate().unwrap();
assert_eq!(sample.len(), 1_000_000);
assert!((sample.mean().unwrap() - 0.5).abs() < 1_000.0 * TEST_ACCURACY)Implementations§
Source§impl LinearCongruentialGenerator
impl LinearCongruentialGenerator
Sourcepub fn new(seed: u32, sample_size: usize, m: u32, a: u32, b: u32) -> Self
pub fn new(seed: u32, sample_size: usize, m: u32, a: u32, b: u32) -> Self
Creates a new LinearCongruentialGenerator instance.
§Input
seed: Seed of the generatorsample_size: Number of pseudo-random numbers to generatem: Mod of the linear congruential generatora: Multiplierof the linear congruential generatorb: Increment of the linear congruential generator
Trait Implementations§
Source§impl Clone for LinearCongruentialGenerator
impl Clone for LinearCongruentialGenerator
Source§fn clone(&self) -> LinearCongruentialGenerator
fn clone(&self) -> LinearCongruentialGenerator
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 LinearCongruentialGenerator
impl Debug for LinearCongruentialGenerator
Source§impl RandomGenerator<LinearCongruentialGenerator> for LinearCongruentialGenerator
impl RandomGenerator<LinearCongruentialGenerator> for LinearCongruentialGenerator
Source§fn new_shuffle(sample_size: usize) -> Result<Self, DigiFiError>
fn new_shuffle(sample_size: usize) -> Result<Self, DigiFiError>
Creates a new LinearCongruentialGenerator instance with random parameters.
§Input
sample_size: Number of pseudo-random numbers to generate
impl Copy for LinearCongruentialGenerator
Auto Trait Implementations§
impl Freeze for LinearCongruentialGenerator
impl RefUnwindSafe for LinearCongruentialGenerator
impl Send for LinearCongruentialGenerator
impl Sync for LinearCongruentialGenerator
impl Unpin for LinearCongruentialGenerator
impl UnsafeUnpin for LinearCongruentialGenerator
impl UnwindSafe for LinearCongruentialGenerator
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.