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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 109d8a,232e89dd4cc3c154,start X-Google-NewGroupId: yes X-Google-Thread: 1014db,232e89dd4cc3c154,start X-Google-NewGroupId: yes X-Google-Thread: 1094ba,232e89dd4cc3c154,start X-Google-NewGroupId: yes X-Google-Thread: 101deb,dea70f96af442ea2 X-Google-NewGroupId: yes X-Google-Thread: 103376,232e89dd4cc3c154,start X-Google-NewGroupId: yes X-Google-Attributes: gid9ef9b79ae9,gid4516fb5702,gid8d3408f8c3,gidbda4de328f,gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!goblin1!goblin3!goblin.stu.neva.ru!exi-transit.telstra.net!news.telstra.net!exi-spool.telstra.net!exi-reader.telstra.net!not-for-mail From: "robin" Newsgroups: sci.math,comp.lang.c,comp.lang.fortran,comp.lang.pl1,comp.lang.ada References: <4dae2a4b$0$55577$c30e37c6@exi-reader.telstra.net> Subject: Re: KISS4691, a potentially top-ranked RNG. Date: Thu, 28 Apr 2011 11:14:49 +1000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6090 Message-ID: <4db90113$0$77724$c30e37c6@exi-reader.telstra.net> NNTP-Posting-Host: 123.3.17.230 X-Trace: 1303970068 exi-reader.telstra.net 77724 123.3.17.230:1039 Xref: g2news2.google.com sci.math:234096 comp.lang.c:126581 comp.lang.fortran:41091 comp.lang.pl1:2414 comp.lang.ada:20036 Date: 2011-04-28T11:14:49+10:00 List-Id: "Uno" wrote in message news:8bfh28Fve1U1@mid.individual.net... | 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. | | $ 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); | } | So, what is all this? In particular, is there something special about | the value of 3.7 billion? No, nothing special at all. The purpose of the exercise is just to confirm that after generating 1000000000 random numbers, you get the same answer as George does.