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,232e89dd4cc3c154 X-Google-NewGroupId: yes X-Google-Thread: 1014db,232e89dd4cc3c154 X-Google-NewGroupId: yes X-Google-Thread: 1094ba,232e89dd4cc3c154 X-Google-NewGroupId: yes X-Google-Thread: 101deb,dea70f96af442ea2 X-Google-NewGroupId: yes X-Google-Thread: 103376,232e89dd4cc3c154 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!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: sci.math,comp.lang.c,comp.lang.fortran,comp.lang.pl1,comp.lang.ada Subject: Re: KISS4691, a potentially top-ranked RNG. Date: Mon, 02 May 2011 07:58:10 +1200 Message-ID: <925saiFj03U7@mid.individual.net> References: <4dae2a4b$0$55577$c30e37c6@exi-reader.telstra.net> <4db90113$0$77724$c30e37c6@exi-reader.telstra.net> <4dbd6e9c$0$12957$892e0abb@auth.newsreader.octanews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 5hR9hO9xcHPUD3EHNqGiSgtC2PYTBbIS8AMIiiFtXCkuUkUA4Y Cancel-Lock: sha1:jGwcKZtO4p0NCKTINSVTPkIE4Dk= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: <4dbd6e9c$0$12957$892e0abb@auth.newsreader.octanews.com> Xref: g2news2.google.com sci.math:234530 comp.lang.c:126723 comp.lang.fortran:41538 comp.lang.pl1:2444 comp.lang.ada:20082 Date: 2011-05-02T07:58:10+12:00 List-Id: On 05/ 2/11 03:31 AM, Thad Smith wrote: > > Here is a modification of the program with masking to produce correct results > with any conforming C implementation. It truncates where when required. A good > optimizer should eliminate the unneeded masking for 32-bit unsigned long. Why oh why can't people just use fixed width types? What's the obsession with unsigned long and masking? Add #include change all references to "unsigned long" to uint32_t, remove all references to M32. > static unsigned long xs = 521288629; > static unsigned long xcng = 362436069; > static unsigned long Q[4691]; > #define M32 0xffffffff > > unsigned long MWC(void) > { > static unsigned long c = 0; > static unsigned long j = 4691; > unsigned long t; > unsigned long x; > j = (j< 4690) ? j + 1 : 0; > x = Q[j]; > t = ((x<< 13) + c)& M32; > if (t< c) { > c = (x>> 19) + 1; > t = (t + x)& M32; > } else { > t = (t + x)& M32; > c = (x>> 19) + (t< x); > } > return (Q[j] = t); > > } > > void initMWC(void) > { > unsigned long i; > for (i = 0; i< sizeof Q / sizeof Q[0]; i++) > Q[i] = ((xcng = 69069 * xcng + 123) + (xs = (xs ^ (xs<< 13))& M32, > xs ^= (xs>> 17), xs ^= (xs<< 5)))& M32; > > } > > #ifdef UNIT_TEST > > #include > > int main() > { > unsigned long i; > unsigned long x; > > initMWC(); > > printf("Does MWC result=3740121002 ?\n"); > for (i = 0; i< 1000000000; i++) > x = MWC(); > printf("%27u\n", x); > > printf("Does KISS result=2224631993 ?\n"); > for (i = 0; i< 1000000000; i++) > x = (MWC() + (xcng = 69069 * xcng + 123) + (xs = (xs ^ (xs<< 13))& M32, > xs ^= (xs>> 17), xs ^= (xs<< 5))); > printf("%27u\n", x); > return 0; > } > > #endif > > > -- Ian Collins