Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simpler version of MWC256? #33

Open
listx opened this issue Aug 1, 2014 · 1 comment
Open

simpler version of MWC256? #33

listx opened this issue Aug 1, 2014 · 1 comment

Comments

@listx
Copy link

listx commented Aug 1, 2014

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?

@OlivierSohn
Copy link
Contributor

OlivierSohn commented Mar 27, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants