I am trying to write a Linear congruential generator in python and I find a little piece of code on Wikipedia but have some difficulty on understanding it. The code is as follows:
def lcg(modulus, a, c, seed=None):
if seed != None:
lcg.previous = seed
random_number = (lcg.previous * a + c) % modulus
lcg.previous = random_number
return random_number / modulus
lcg.previous = 2222
My problem is that what is "lcg.previous
"? I notice that the function is done, the value of lcg.previous
gets updated and stored. Is it declared as a member variable of function lcg() here or actually some kind of default set up for all function in python?
Thanks a lot!