Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Implementing the KISS4691 RNG
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ian Collins  
View profile  
 More options Sep 5 2010, 5:19 pm
Newsgroups: sci.math, comp.lang.c, comp.lang.fortran
From: Ian Collins <ian-n...@hotmail.com>
Date: Mon, 06 Sep 2010 09:19:56 +1200
Local: Sun, Sep 5 2010 5:19 pm
Subject: Re: Implementing the KISS4691 RNG
On 09/ 6/10 09:04 AM, geo wrote:

<snip>

> Thus I suggest using this listing for the MWC function
> in KISS4691:
> ------------------------------------------------

>   unsigned long MWC(void)
>   {unsigned long t,x; static c=0,j=4691;

static what?

>     j=(j<4690)? j+1:0;
>     x=Q[j]; t=(x<<13)+c;
>       if(t<c) {c=(x>>19)+1; t=t+x;}
>       else {t=t+x; c=(x>>19)+(t<x);}
>     return (Q[j]=t);
>   }

This code must be making assumptions about sizes, it gives different
results in 32 and 64 bit mode.

> ------------------------------------------------

> and recommend that it be the pattern for implementations in
> PL/I, asm, Fortran or others.  For signed integers, flip the
> sign bits so that t<x becomes (t^m)<(x^m) or equivalents.
> (C versions using signed integers should also avoid the
> problem of right shifts, replacing (x>>19) by
> ((unsigned)x>>19) or ((unsigned)xs>>17) in the XS component.)

> In case you do not have, or don't want to fetch, the original,
> here is the entire listing, with the recommended form for MWC():

> ------------------------------------------------------------
> static unsigned long xs=521288629,xcng=362436069,Q[4691];

> unsigned long MWC(void)
> {unsigned long t,x; static c=0,j=4691;
>    j=(j<4690)? j+1:0;
>    x=Q[j]; t=(x<<13)+c;
>      if(t<c) {c=(x>>19)+1; t=t+x;}
>      else {t=t+x; c=(x>>19)+(t<x);}
>    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 )

> #include<stdio.h>
> int main()
> {unsigned long i,x;
>   for(i=0;i<4691;i++)  Q[i]=CNG+XS;
> 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=KISS;
>     printf("%27u\n",x);
> }

Try compiling with warnings enabled!

--
Ian Collins


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.