Sunday, September 26, 2010

values of a for small lag CMWC RNGs

See wikipedia for more info.

In short, we need a*b^r+1 to be prime, and to have b as a primitive root.


abrperiod (roughly)
22228-11215.8
23828-12223.9
25428-14240
16628-18271.3
10628-1162134.6
65518216-11232
65474216-12248
65398216-14280
65486216-182144
65234216-1162272
65518216-1322528
62826216-16421039.9
62378216-112822063.9
55962216-125624111.8
4294967274232-11264
4294966926232-12296
4294967030232-142160
4294967054232-182288
4294966302232-1162544
4294965894232-13221056
4294966718232-16422080
4294961686232-112824128
4294944438232-125628224


for something different, here's a Python generator.


def cmwc_r1(x=0,c=0,a=65518,b=2**16-1):
while True:
t=a*x+c
c=t/b
x=(b-1)-(t%b)
yield x

rng=cmwc_r1(x=123,c=456)

for n in rng:
print '%5d' % (n)

No comments: