mwc-random icon indicating copy to clipboard operation
mwc-random copied to clipboard

simpler version of MWC256?

Open listx opened this issue 11 years ago • 1 comments

I found a different (simpler) version of MWC256 that George Marsaglia himself posted on the internet. It has the same 2^8222 period and Marsaglia vetted the quality of the PRNG as well. The version that we currently use comes from Feb 25, 2003 https://groups.google.com/d/msg/sci.math/k3kVM8KwR-s/jxPdZl8XWZkJ:

static unsigned long Q[256],c=362436;
unsigned long MWC256(void){
  unsigned long long t,a=1540315826LL;
  unsigned long x;
  static unsigned char i=255;
     t=a*Q[++i]+c; c=(t>>32);
     x=t+c;     if(x<c){x++;c++;}
     return(Q[i]=x);       }

Another version comes from May 13, 2003 https://groups.google.com/d/msg/comp.lang.c/qZFQgKRCQGg/rmPkaRHqxOMJ:

static unsigned long Q[256],c=362436;  /* choose random initial c<809430660 and */
                                       /* 256 random 32-bit integers for Q[] */

unsigned long MWC256(void){
  unsigned long long t,a=809430660LL;
  static unsigned char i=255;
     t=a*Q[++i]+c; c=(t>>32);
     return(Q[i]=t);      }

Why was the first version chosen for mwc-random?

listx avatar Aug 01 '14 16:08 listx

After having read https://en.wikipedia.org/wiki/Multiply-with-carry#Complementary-multiply-with-carry_generators, I think that the version with x=t+c; if(x<c){x++;c++;} is CMWC256. In the first post (https://groups.google.com/d/msg/sci.math/k3kVM8KwR-s/jxPdZl8XWZkJ), George Marsaglia probably made a mistake and used the name MWC256 in place of CMWC256, where 'C' in the name stands for complementary.

Then, if I'm correct, this module should actually be named cmwc-random, as it implements the complementary version.

OlivierSohn avatar Mar 27 '18 11:03 OlivierSohn