lcg.Rd
A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. The method represents one of the oldest and best-known pseudorandom number generator algorithms. The theory behind them is relatively easy to understand, and they are easily implemented and fast, especially on computer hardware which can provide modular arithmetic by storage-bit truncation.
lcg(seed, n, m = 65537L, a = 75L, c = 74L)
initial starting value
the number of random numbers you want to create.
modulus argument. By default, \(m = 2^{16} + 1\) (follows ZX81 configuration)
multiplier argument. By default, \(a = 75\) (follows ZX81 configuration)
increment argument By default, \(c = 74\) (follows ZX81 configuration)
The generator is defined by the recurrence relation: $$X_{n+1} = (aX + c) \text{ mod } m$$ Where \(X\) is the sequence of pseudo-random values and
- \(m, 0 < m\) - the "modulus"
- \(a, 0 < a < m\) - the "multiplier"
- \(c, 0 \le c < m\) - the "increment"
- \(X_0, 0 \le X_0 < m\) - the "seed" or "start value"
For more information see the Wikipedia page.
random_numbers <- lcg(1234, 1000)
# Plot numbers to see that they are random
plot(random_numbers)