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 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: g2news1.google.com!news2.google.com!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.brown.octanews.com.POSTED!not-for-mail Date: Sun, 01 May 2011 08:31:11 -0700 From: Thad Smith User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: sci.math,comp.lang.c,comp.lang.fortran,comp.lang.pl1,comp.lang.ada Subject: Re: KISS4691, a potentially top-ranked RNG. References: <4dae2a4b$0$55577$c30e37c6@exi-reader.telstra.net> <4db90113$0$77724$c30e37c6@exi-reader.telstra.net> In-Reply-To: <4db90113$0$77724$c30e37c6@exi-reader.telstra.net> Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAABGdBTUEAAK/INwWK6QAAABl0 RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAGUExURQAAAP///6XZn90AAAEiSURB VHjajJVRkoUwCAQ797/01nM1MjAQU+WHSssEB8IKC1ZZ+RnxlYkvCMf4ROByTQQf4oX4BhghHIDy 4Tm+ApiQXxBP7RKAVPdePoUCNbAQCGatoTkDYL8OieBJ54VH6XcZ/u8we00318UrhufRLqfVdwHX yzfEF5aY6ZYWfmer7wVIvZSQIHqxN17/Fby/s5TW+GNJSbYOyUAuKrt0e/PYflB/qVtZdgO63QT0 HYTuj2N/guk4vk0MaSDbC6paLULf9mRJpqzRsgUIjSFWE/vkoon1Ul+SJp8xf41vADqidT5DliNg B0OZU5ihtEbgeCwypjBGG+rRmO9ElHM6E7ns83S+LTQdxlQiz4gTgJ+Vg6T5HPYJhrnQSOrHwp8A AwCyFgY4Ien7rQAAAABJRU5ErkJggg== Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4dbd6e9c$0$12957$892e0abb@auth.newsreader.octanews.com> Organization: Octanews NNTP-Posting-Date: 01 May 2011 09:30:54 CDT X-Complaints-To: abuse@octanews.net Xref: g2news1.google.com sci.math:217366 comp.lang.c:115430 comp.lang.fortran:39181 comp.lang.pl1:2326 comp.lang.ada:19110 Date: 2011-05-01T09:30:54-05:00 List-Id: On 4/27/2011 6:14 PM, robin wrote: > "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. 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. 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 -- Thad