Linear congruential generator in python 1

Linear congruential generator in python

def rng(m=2**32, a=1103515245, c=12345):
    rng.current = (a*rng.current + c) % m
    return rng.current/m

# setting the seed
rng.current = 1
for i in range(10):
  rng()

Here is what the above code is Doing:
1. Define a function called rng that takes in a value m, a value a, and a value c.
2. Set the current value of rng to the current value of rng times a plus c, modulo m.
3. Return the current value of rng divided by m.
4. Set the current value of rng to 1.
5. Call rng 10 times.

Similar Posts