I am trying to write a linear congruent generator in python, and I find a small piece of code on Wikipedia , but with some difficulty understanding this. 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 what is the " lcg.previous"? I noticed that the function is complete, the value is lcg.previousupdated and saved. Is it declared as a member variable of the lcg () function here or is it actually some kind of default setting for all functions in python?
Thank you so much!
source
share