From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 109d8a,ea40acba15d5d078 X-Google-NewGroupId: yes X-Google-Thread: 1014db,ea40acba15d5d078 X-Google-NewGroupId: yes X-Google-Thread: 1094ba,ea40acba15d5d078 X-Google-NewGroupId: yes X-Google-Thread: 101deb,620e03552eca5f22 X-Google-NewGroupId: yes X-Google-Thread: 103376,c5d0be666830517 X-Google-NewGroupId: yes X-Google-Attributes: gid9ef9b79ae9,gid4516fb5702,gid8d3408f8c3,gidbda4de328f,gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,CP1252 Path: g2news1.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Uno Newsgroups: sci.math,comp.lang.c,comp.lang.fortran,comp.lang.pl1,comp.lang.ada Subject: Re: KISS4691, a potentially top-ranked RNG. Date: Fri, 30 Jul 2010 02:33:13 -0600 Message-ID: <8bfh28Fve1U1@mid.individual.net> References: <4c4ecbef$0$12393$c30e37c6@exi-reader.telstra.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net dyFDAVH+FIOX9MnpwJyqiwQLgZELy2o1D88+ddlDz4wkanjd8X Cancel-Lock: sha1:midMHat7d54Xonr0ZAdcXZueFeg= User-Agent: Thunderbird 2.0.0.24 (X11/20100317) In-Reply-To: <4c4ecbef$0$12393$c30e37c6@exi-reader.telstra.net> Xref: g2news1.google.com sci.math:175417 comp.lang.c:98967 comp.lang.fortran:26096 comp.lang.pl1:1581 comp.lang.ada:12701 Date: 2010-07-30T02:33:13-06:00 List-Id: robin wrote: > "jacob navia" wrote in message news:i2fir2$op4$1@speranza.aioe.org... > > | This doesn't work with systems that have unsigned long as a 64 bit quantity. > | > | I obtain: > | > | MWC result=3740121002 ? > | 4169348530 > | KISS result=2224631993 ? > | 1421918629 > > For a 64-bit machine (using 64-bit integer arithmetic), > you'd need to truncate each result to 32 bits. That not > only applies to the multiplication, it also applies to addition, etc. > On a 32-bit machine, these extra bits are discarded, > but in 64-bit arithmetic, they are retained, > and unless they are similarly discarded, > you won't get the same results. > I suggest using IAND(k, 2*2147483647+1) > for the truncation. > > With such modifications in the program, > it should then produce the same results on both 32-bit and > 64-bit machines. > > P.S. the product 2*2... is best obtained using ISHFT. > > | Compiling with 32 bit machine yields: > | MWC result=3740121002 ? > | 3740121002 > | KISS result=2224631993 ? > | 2224631993 > > > First of all, I think we're talking to the actual George Marsaglia here. Thank you so much for posting. You may have displaced Terence as our senior member. Are you creating bigger numbers just to accomodate your age?:-) $ gcc -Wall -Wextra geo1.c -o out geo1.c: In function �MWC�: geo1.c:5: warning: type defaults to �int� in declaration of �c� geo1.c:5: warning: type defaults to �int� in declaration of �j� geo1.c:5: warning: unused variable �i� geo1.c: In function �main�: geo1.c:21: warning: format �%22u� expects type �unsigned int�, but argument 2 has type �long unsigned int� geo1.c:23: warning: format �%22u� expects type �unsigned int�, but argument 2 has type �long unsigned int� geo1.c:24: warning: control reaches end of non-void function $ ./out MWC result=3740121002 ? 3740121002 KISS result=2224631993 ? 2224631993 $ cat geo1.c static unsigned long xs=521288629,xcng=362436069,Q[4691]; unsigned long MWC(void) /*takes about 4.2 nanosecs or 238 million/ second*/ {unsigned long t,x,i; static c=0,j=4691; j=(j<4690)? j+1:0; x=Q[j]; t=(x<<13)+c+x; c=(t>19); return (Q[j]=t); } #define CNG ( xcng=69069*xcng+123 ) #define XS ( xs^=(xs<<13), xs^=(xs>>17), xs^=(xs<<5) ) #define KISS ( MWC()+CNG+XS ) /*138 million/sec*/ #include int main() {unsigned long i,x; for(i=0;i<4691;i++) Q[i]=CNG+XS; for(i=0;i<1000000000;i++) x=MWC(); printf(" MWC result=3740121002 ?\n%22u\n",x); for(i=0;i<1000000000;i++) x=KISS; printf("KISS result=2224631993 ?\n%22u\n",x); } // gcc -Wall -Wextra geo1.c -o out $ So, what is all this? In particular, is there something special about the value of 3.7 billion? -- Uno