Linear Congruential Generator
Revisão de 17h00min de 28 de dezembro de 2020 por Abaffa (discussão | contribs) (Criou página com 'CategoryPseudorandom number generators')
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
commoldura|direita|1 million attempts using LCG
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