I am writing a LCG function in Python that I will use for a Monte Carlo type simulation for coin flips and generating runs. The problem I am facing is that when I generate a list of random numbers, the numbers are patterned such that odds and evens alternate. I don't know whether that is a property of the LCG function itself or a mistake in how I am generating the numbers.
Here is my code:
def seedLCG(initVal):
global rand
rand = initVal
def lcg():
a = 1140671485
c = 128201163
m = 2**24
global rand
rand = (a*rand + c) % m
return rand
seedLCG(1)
for i in range(10):
print lcg()
Values Returned:
10581448
11595891
1502322
14136437
11348076
1403015
9622582
11013417
11529808
15836891
I'm assuming I don't need to worry about overflow and size because int and long are interchanged as needed by Python.