The LCG is one of the oldest ways of generating a pseudo-random number sequence. It follows a simple, recursive formula:
X denotes the random number (or, more precisely, the nth random number in the sequence). It is based on its predecessor multiplied by a factor, a, and offset by a constant, c. The modulo operator makes sure that there is no overflow. What's the first X? The seed! So a random number sequence will start with the seed, providing determinism if needed.
These parameter settings are subject to significant testing; in fact, many library and compiler developers have different settings. The Wikipedia page provides an overview (https://en.wikipedia.org/wiki/Linear_congruential_generator):
pub struct LCG {
xn: f32,
m: f32,
c: f32,
a: f32,
}
impl LCG {
fn seeded(seed: u32) -> LCG {
LCG {
xn: seed as f32,
m: 2e31,
a: 171f32,
c: 8f32,
}
}
fn new(seed: f32, m: f32, a: f32, c: f32) -> LCG ...