comp.lang.ada
 help / color / mirror / Atom feed
From: Uno <merrilljensen@q.com>
Subject: Re: KISS4691, a potentially top-ranked RNG.
Date: Fri, 30 Jul 2010 02:33:13 -0600
Date: 2010-07-30T02:33:13-06:00	[thread overview]
Message-ID: <8bfh28Fve1U1@mid.individual.net> (raw)
In-Reply-To: <4c4ecbef$0$12393$c30e37c6@exi-reader.telstra.net>

robin wrote:
> "jacob navia" <jacob@spamsink.net> 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<x)+(x>>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 <stdio.h>
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



  reply	other threads:[~2010-07-30  8:33 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <a82cebe3-cdb9-48af-8080-bca935eeb9b1@l14g2000yql.googlegroups.com>
2010-07-25  0:49 ` KISS4691, a potentially top-ranked RNG Gene
2010-07-26  2:50   ` robin
2010-07-27  5:46 ` robin
2010-07-30 10:46   ` Uno
2010-08-03 10:41     ` robin
2010-08-03 17:15       ` James Waldby
2010-08-03 17:35         ` Dann Corbit
2010-08-03 20:34           ` Peter Flass
2010-08-04  4:20             ` Uno
2010-08-04  8:31           ` robin
2010-08-04  7:56         ` robin
2010-08-05 21:07           ` Uno
2010-08-06 10:11             ` robin
2010-08-09 14:52             ` mecej4
     [not found] ` <i2fir2$op4$1@speranza.aioe.org>
2010-07-27 10:19   ` robin
2010-07-30  8:33     ` Uno [this message]
     [not found] <4dae2a4b$0$55577$c30e37c6@exi-reader.telstra.net>
2011-04-28  1:14 ` robin
2011-04-28 11:42   ` e p chandler
2011-04-29  1:50     ` David Bernier
2011-04-29  2:09       ` Ian Collins
2011-04-29  3:01         ` Eric Sosman
2011-04-29  3:09           ` Ian Collins
2011-05-08  7:34             ` Uno
2011-05-11  5:38               ` Marni Zollinger
2011-04-29  6:15           ` nmm1
2011-04-29  3:16         ` David Bernier
2011-04-29  2:34       ` glen herrmannsfeldt
2011-04-29  7:04         ` Uno
2011-04-30 10:48           ` robin
2011-05-05  1:12             ` Uno
2011-04-29 15:13         ` Keith Thompson
2011-04-29 17:41           ` glen herrmannsfeldt
2011-04-29 19:53             ` Keith Thompson
2011-05-05 23:38               ` Michael Press
2011-04-29 22:45           ` Seebs
2011-04-30  4:36           ` Randy Brukardt
2011-04-29 22:43       ` Seebs
2011-04-29  9:43     ` robin
2011-05-01 15:31   ` Thad Smith
2011-05-01 19:58     ` Ian Collins
2011-05-02  0:01       ` James Kuyper
2011-05-02  0:42         ` Ian Collins
2011-05-02  2:34           ` James Kuyper
2011-05-02  2:50           ` glen herrmannsfeldt
2011-05-02  4:21       ` Thad Smith
2011-05-02  7:31         ` nmm1
2011-05-23  4:18           ` robin
2011-05-23  7:20             ` robin
2011-05-23  6:52           ` robin
2011-05-23  6:52           ` robin
2011-05-23  6:52           ` robin
2011-05-23  6:53           ` robin
2011-05-23  7:16             ` Georg Bauhaus
2011-06-28  7:19               ` robin
2011-06-28  8:44                 ` Vinzent Hoefler
2011-06-28  9:19                   ` Chris H
2011-06-28  9:14                 ` Georg Bauhaus
2011-06-28 11:59                   ` robin
2011-06-28 12:16                     ` Chris H
2011-06-28 15:44                       ` Peter Flass
2011-06-28 12:33                     ` James Kuyper
2011-06-28 13:53                     ` Georg Bauhaus
2011-06-28 22:39                       ` Brian Salter-Duke
2011-06-28 12:32                 ` James Kuyper
2011-06-28 13:03                   ` Chris H
2011-06-28 14:25                     ` James Kuyper
2011-06-28 15:01                       ` Chris H
2011-06-29  0:20                         ` James Kuyper
2011-06-29  8:38                         ` Michael Press
2011-06-28 16:04                 ` Joe Pfeiffer
2011-06-28 16:36                   ` Chris H
2011-06-28 16:51                     ` Joe Pfeiffer
2011-06-29  0:27                       ` James Kuyper
2011-06-29  1:00                         ` Joe Pfeiffer
2011-06-29 16:48                         ` Phil Carmody
2011-06-28 16:52                     ` Joe Pfeiffer
2011-06-28 17:06                     ` David Bernier
2011-06-28 21:11                     ` Gib Bogle
2011-06-29  4:47                       ` Mart van de Wege
2011-07-02  6:49                         ` Gib Bogle
2011-07-02 15:59                           ` Mart van de Wege
2011-07-02 21:57                             ` Gib Bogle
2011-06-29  7:36                       ` nmm1
2011-06-29  9:58                         ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox