Linear Congruential Generator
Ir para navegação
Ir para pesquisar
A linear congruential generator (LCG), is an algorithm that produces a sequence of pseudo-random numbers calculated with a piecewise linear equation.
We will use a linear recurrence relation as follows,
where m and p are two suitably chosen integers.
And the uniform random variates are obtained after scaling,
Sample Python Code
def pseudo_uniform_good(mult=16807,mod=(2**31)-1,seed=123456789,size=1):
"""
A reasoanbly good pseudo random generator
"""
U = np.zeros(size)
x = (seed * mult + 1) % mod
U[0] = x / mod
for i in range(1, size):
x = (x * mult + 1) % mod
U[i] = x / mod
return U