Web Images News Groups Scholar Blogs Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
RNGs: A Super KISS
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
geo  
View profile  
 More options Nov 3, 3:46 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: geo <gmarsag...@gmail.com>
Date: Tue, 3 Nov 2009 07:46:27 -0800 (PST)
Local: Tues, Nov 3 2009 3:46 pm
Subject: RNGs: A Super KISS
/*
For those mesmerized (or Mersenne-ized?) by a RNG
with period 2^19937-1, I offer one here with period
54767*2^1337279---over 10^396564 times as long.
It is one of my CMWC (Complimentary-Multiply-With-Carry) RNGs,
and is suggested here as one of the components of a
super-long-period KISS (Keep-It-Simple-Stupid) RNG.

With b=2^32 and a=7010176, and given a 32-bit x, and a 32-bit c, this
generator produces a new x,c by forming 64-bit t=a*x+c then replacing:
c=top 32 bits of t and x=(b-1)-(bottom 32 bits of t). In C: c=t>>32;
x=~t;

For many years, CPUs have had machine instructions to form such a
64-bit t and extract the top and bottom halves, but unfortunately
only recent Fortran versions have means to easily invoke them.

Ability to do those extractions leads to implementations that are
simple
and extremely fast---some 140 million per second on my desktop PC.

Used alone, this generator passes all the Diehard Battery of Tests,
but
its simplicity makes it well-suited to serve as one of the three
components
of a KISS RNG, based on the Keep-It-Simple-Stupid principle, and the
idea,
supported by both theory and practice, that the combination of RNGs
based on
different mathematical models can be no worse---and is usually
better---than
any of the components.

So here is a complete C version of what might be called a SUPER KISS
RNG,
combining, by addition mod 2^32, a Congruential RNG, a Xorshift RNG
and the super-long-period CMWC RNG:
*/

#include <stdio.h>
static unsigned long Q
[41790],indx=41790,carry=362436,xcng=1236789,xs=521288629;

#define CNG ( xcng=69609*xcng+123 )    /*Congruential*/
#define XS  ( xs^=xs<<13, xs^=(unsigned)xs>>17, xs^=xs>>5 )  /
*Xorshift*/
#define SUPR ( indx<41790 ? Q[indx++] : refill() )
#define KISS SUPR+CNG+XS

  int refill( )
  { int i; unsigned long long t;
  for(i=0;i<41790;i++) { t=7010176LL*Q[i]+carry; carry=(t>>32); Q[i]=~
(t);}
  indx=1; return (Q[0]);
  }

int main()
{unsigned long i,x;
 for(i=0;i<41790;i++) Q[i]=CNG+XS;
 for(i=0;i<1000000000;i++) x=KISS;
 printf("     x=%d.\nDoes x=-872412446?\n",x);

}

/*
Running this program should produce 10^9 KISSes in some 7-15 seconds.
You are invited to cut, paste, compile and run for yourself, checking
to
see if the last value is as designated, (formatted as a signed integer
for
potential comparisons with systems using signed integers).
You may want to report or comment on implementations for other
languages.

The arithmetic operations are suited for either signed or unsigned
integers.
Thus, with  (64-bit)t=a*x+c,  x=t%b in C or x=mod(t,b) in Fortran, and
c=c/b in either C or Fortran, but with ways to avoid integer
divisions,
and subsequent replacement of x by its base-b complement, ~x in C.

With b=2^32 and p=54767*2^1337287+1, the SUPR part of this Super KISS
uses my CMWC method to produce, in reverse order, the base-b expansion
of k/p for some k determined by the values used to seed the Q array.
The period is the order of b for that prime p:
   54767*2^1337279, about 2^1337294 or 10^402566.
(It took a continuous run of 24+ days on an earlier PC to
establish that order.  My thanks to the wizards behind PFGW
and to Phil Carmody for some suggested code.)

Even the Q's all zero, should seeding be overlooked in main(),
will still produce a sequence of the required period, but will
put the user in a strange and exceedingly rare place in the entire
sequence.  Users should choose a reasonable number of the 1337280
random bits that a fully-seeded  Q array requires.

Using your own choices of merely 87 seed bits, 32 each for xcng,xs
and 23 for carry<7010176, then initializing the Q array with
            for(i=0;i<41790;i++) Q[i]=CNG+XS;
should serve well for many applications, but others, such as in
Law or Gaming, where a minimum number of possible outcomes may be
required, might need more of the 1337280 seed bits for the Q array.

As might applications in cryptography: With an unknown but fully-
seeded Q array, a particular string of, say, 41000 successive SUPR
values will appear at more than 2^20000 locations in the full
sequence,
making it virtually impossible to get the location of that particular
string in the full loop, and thus predict coming or earlier values,
even if able to undo the CNG+XS operations.
*/

/*
So I again invite you to cut, paste, compile and run the above C
program.
1000 million KISSes should be generated, and the specified result
appear,
by the time you count slowly to fifteen.
(Without an optimizing compiler, you may have to count more slowly.)
*/

/* George Marsaglia */


    Reply    Reply to author    Forward  
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.
user923005  
View profile  
 More options Nov 3, 8:23 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt, comp.lang.c++
From: user923005 <dcor...@connx.com>
Date: Tue, 3 Nov 2009 12:23:57 -0800 (PST)
Local: Tues, Nov 3 2009 8:23 pm
Subject: Re: RNGs: A Super KISS
On Nov 3, 7:46 am, geo <gmarsag...@gmail.com> wrote:

/*
Here is a C++ version.  The C version is quite a bit faster
because there are no function calls at all.
Can any of you C++ gurus bump the speed without losing encapsulation?
I get about 5 seconds for the C version and about 8 seconds for the
C++ version.

-- d.corbit
*/

#include <iostream>
/*
For those mesmerized (or Mersenne-ized?) by a RNG
with period 2^19937-1, I offer one here with period
54767*2^1337279---over 10^396564 times as long.
It is one of my CMWC (Complimentary-Multiply-With-Carry) RNGs,
and is suggested here as one of the components of a
super-long-period KISS (Keep-It-Simple-Stupid) RNG.

With b=2^32 and a=7010176, and given a 32-bit x, and a 32-bit c, this
generator produces a new x,c by forming 64-bit t=a*x+c then replacing:
c=top 32 bits of t and x=(b-1)-(bottom 32 bits of t). In C: c=t>>32;
x=~t;

For many years, CPUs have had machine instructions to form such a
64-bit t and extract the top and bottom halves, but unfortunately
only recent Fortran versions have means to easily invoke them.

Ability to do those extractions leads to implementations that are
simple
and extremely fast---some 140 million per second on my desktop PC.

Used alone, this generator passes all the Diehard Battery of Tests,
but
its simplicity makes it well-suited to serve as one of the three
components
of a KISS RNG, based on the Keep-It-Simple-Stupid principle, and the
idea,
supported by both theory and practice, that the combination of RNGs
based on
different mathematical models can be no worse---and is usually
better---than
any of the components.

So here is a complete C version of what might be called a SUPER KISS
RNG,
combining, by addition mod 2^32, a Congruential RNG, a Xorshift RNG
and the super-long-period CMWC RNG:
*/

class SuperKiss {

private:
    unsigned long  Q[41790];
    unsigned long  indx;
    unsigned long  carry;
    unsigned long  xcng;
    unsigned long  xs;

    int refill ()
    {
        int i;
        unsigned long long t;
        for (i = 0; i < 41790; i++)
        {
            t = 7010176LL * Q[i] + carry;
            carry = (t >> 32);
            Q[i] = ~(t);
        }
        indx = 1;
        return (Q[0]);
    }

public:
    // Constructor:
    SuperKiss()
    {
        indx  = 41790;
        carry = 362436;
        xcng  = 1236789;
        xs    = 521288629;
        unsigned i;
        for (i = 0; i < 41790; i++)
            Q[i] = (xcng = 69609 * xcng + 123) +
                   (xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^=
xs >> 5);
    }

    // Collect next random number:
    unsigned long SKRand() {
        return (indx < 41790 ? Q[indx++] : refill ()) +
               (xcng = 69609 * xcng + 123) +
               (xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^= xs >>
5);
    }

};

int
main ()
{
    unsigned long i
    int x;
    SuperKiss sk;
    for (i = 0; i < 1000000000; i++)
        x = sk.SKRand();
    std::cout << " x = " << x << std::endl << "does Does
x=-872412446?" << std::endl;
    return 0;

}

/*
Running this program should produce 10^9 KISSes in some 7-15 seconds.
You are invited to cut, paste, compile and run for yourself, checking
to
see if the last value is as designated, (formatted as a signed integer
for
potential comparisons with systems using signed integers).
You may want to report or comment on implementations for other
languages.

The arithmetic operations are suited for either signed or unsigned
integers.
Thus, with  (64-bit)t=a*x+c,  x=t%b in C or x=mod(t,b) in Fortran, and
c=c/b in either C or Fortran, but with ways to avoid integer
divisions,
and subsequent replacement of x by its base-b complement, ~x in C.

With b=2^32 and p=54767*2^1337287+1, the SUPR part of this Super KISS
uses my CMWC method to produce, in reverse order, the base-b expansion
of k/p for some k determined by the values used to seed the Q array.
The period is the order of b for that prime p:
54767*2^1337279, about 2^1337294 or 10^402566.
(It took a continuous run of 24+ days on an earlier PC to
establish that order.  My thanks to the wizards behind PFGW
and to Phil Carmody for some suggested code.)

Even the Q's all zero, should seeding be overlooked in main(),
will still produce a sequence of the required period, but will
put the user in a strange and exceedingly rare place in the entire
sequence.  Users should choose a reasonable number of the 1337280
random bits that a fully-seeded  Q array requires.

Using your own choices of merely 87 seed bits, 32 each for xcng,xs
and 23 for carry<7010176, then initializing the Q array with
for(i=0;i<41790;i++) Q[i]=CNG+XS;
should serve well for many applications, but others, such as in
Law or Gaming, where a minimum number of possible outcomes may be
required, might need more of the 1337280 seed bits for the Q array.

As might applications in cryptography: With an unknown but fully-
seeded Q array, a particular string of, say, 41000 successive SUPR
values will appear at more than 2^20000 locations in the full
sequence,
making it virtually impossible to get the location of that particular
string in the full loop, and thus predict coming or earlier values,
even
...

read more »


    Reply    Reply to author    Forward  
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.
Tom St Denis  
View profile  
 More options Nov 3, 8:32 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: Tom St Denis <t...@iahu.ca>
Date: Tue, 3 Nov 2009 12:32:54 -0800 (PST)
Local: Tues, Nov 3 2009 8:32 pm
Subject: Re: RNGs: A Super KISS
On Nov 3, 10:46 am, geo <gmarsag...@gmail.com> wrote:

>   int refill( )
>   { int i; unsigned long long t;
>   for(i=0;i<41790;i++) { t=7010176LL*Q[i]+carry; carry=(t>>32); Q[i]=~
> (t);}
>   indx=1; return (Q[0]);
>   }

Not to nitpick but your C code could use some work.  First off, some
indentation please?  Second, returning a unsigned long long as "int"
is not very portable.

Part of the good thing of PRNGs is that they're reproduceable.
Ideally over different platforms.  You should truncate the return
value if you want it as "int" or change the return type.  As it stands
now this will produce different results on my x86-32 and 64 boxes for
the same seed, which is a bad thing.

Tom


    Reply    Reply to author    Forward  
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.
user923005  
View profile  
 More options Nov 3, 8:36 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt, comp.lang.c++
From: user923005 <dcor...@connx.com>
Date: Tue, 3 Nov 2009 12:36:15 -0800 (PST)
Local: Tues, Nov 3 2009 8:36 pm
Subject: Re: RNGs: A Super KISS
On Nov 3, 12:23 pm, user923005 <dcor...@connx.com> wrote:
I copied and pasted from the wrong file.  Here is the correct code
[snip]
class SuperKiss {

private:
    unsigned long  Q[41790];
    unsigned long  indx;
    unsigned long  carry;
    unsigned long  xcng;
    unsigned long  xs;

    int refill ()
    {
        int i;
        unsigned long long t;
        for (i = 0; i < 41790; i++)
        {
            t = 7010176LL * Q[i] + carry;
            carry = (t >> 32);
            Q[i] = ~(t);
        }
        indx = 1;
        return (Q[0]);
    }

public:
    // Constructor:
    SuperKiss()
    {
        indx  = 41790;
        carry = 362436;
        xcng  = 1236789;
        xs    = 521288629;
        unsigned i;
        for (i = 0; i < 41790; i++)
            Q[i] = (xcng = 69609 * xcng + 123) +
                   (xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^=
xs >> 5);
    }

    // Collect next random number:
    unsigned long SKRand() {
        return (indx < 41790 ? Q[indx++] : refill ()) +
               (xcng = 69609 * xcng + 123) +
               (xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^= xs >>
5);
    }

};

int
main ()
{
    unsigned long i;
    int x=0;
    SuperKiss sk;
    for (i = 0; i < 1000000000; i++)
        x = sk.SKRand();
    std::cout << "   x = " << x << std::endl << "Does x=-872412446?"
<< std::endl;
    return 0;


    Reply    Reply to author    Forward  
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.
James Waldby  
View profile  
 More options Nov 3, 8:39 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: James Waldby <n...@no.no>
Date: Tue, 03 Nov 2009 14:39:02 -0600
Local: Tues, Nov 3 2009 8:39 pm
Subject: Re: RNGs: A Super KISS

I've snipped the program except for three lines that apparently must
differ depending upon cpu word length.  On my 64-bit Athlon X2 5200+
(1GHz) with gcc 4.1.2, and %d changed to %ld, the output (after 7.5
seconds) contains "x=2904265093743181565."; or, with instead long
changed to int in two places,  "x=-872412446." (after 7.3 seconds).

--
jiw


    Reply    Reply to author    Forward  
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.
James Waldby  
View profile  
 More options Nov 3, 8:43 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: James Waldby <n...@no.no>
Date: Tue, 03 Nov 2009 14:43:06 -0600
Local: Tues, Nov 3 2009 8:43 pm
Subject: Re: RNGs: A Super KISS

Note, in hexadecimal those results are 284e05b71e20fefd and cc000ae2
respectively.  Ie, the bit patterns of the low 32 bits are quite
different.

--
jiw


    Reply    Reply to author    Forward  
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.
user923005  
View profile  
 More options Nov 3, 9:16 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: user923005 <dcor...@connx.com>
Date: Tue, 3 Nov 2009 13:16:07 -0800 (PST)
Local: Tues, Nov 3 2009 9:16 pm
Subject: Re: RNGs: A Super KISS
On Nov 3, 12:39 pm, James Waldby <n...@no.no> wrote:

I get the same results on:
64 bit Windows using the 64 bit MS compiler
64 bit Windows using the 32 bit MS compiler
64 bit Windows using the 64 bit Mingw GCC compiler
64 bit OpenVMS (Itanium) using HP CXX
64 bit OpenVMS (Alpha) using HP CXX
32 bit OpenVMS (VAX) using HP CXX (Had to remove the std:: because of
old compiler, expect a very long wait)
Solaris 5.9 is interesting because it is big-endian, in contrast with
those previously mentioned:
/export/home/dcorbit> uname -a
SunOS solaris9 5.9 Generic_118558-11 sun4u sparc SUNW,Sun-Fire-V210
/export/home/dcorbit> gcc --version
gcc (GCC) 4.0.2
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
/export/home/dcorbit> ./a.out
   x = -872412446
Does x=-872412446?
/export/home/dcorbit>

    Reply    Reply to author    Forward  
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.
Dann Corbit  
View profile  
 More options Nov 3, 9:24 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: Dann Corbit <dcor...@connx.com>
Date: Tue, 3 Nov 2009 13:24:36 -0800
Local: Tues, Nov 3 2009 9:24 pm
Subject: Re: RNGs: A Super KISS
In article <4fd3c8bf-e45b-4359-ac50-f54298b14770
@d21g2000yqn.googlegroups.com>, t...@iahu.ca says...

> On Nov 3, 10:46 am, geo <gmarsag...@gmail.com> wrote:
> >   int refill( )
> >   { int i; unsigned long long t;
> >   for(i=0;i<41790;i++) { t=7010176LL*Q[i]+carry; carry=(t>>32); Q[i]=~
> > (t);}
> >   indx=1; return (Q[0]);
> >   }

> Not to nitpick but your C code could use some work.  First off, some
> indentation please?  Second, returning a unsigned long long as "int"
> is not very portable.

The O.P. is George Marsaglia.  If there were a Mt. Rushmore for computer
science, Donald Knuth would be George Washington's bust, but Marsaglia
would be up there somewhere too.  If it were random numbers, then Mr.
Marsaglia is front and center.

IMO-YMMV

> Part of the good thing of PRNGs is that they're reproduceable.
> Ideally over different platforms.  You should truncate the return
> value if you want it as "int" or change the return type.  As it stands
> now this will produce different results on my x86-32 and 64 boxes for
> the same seed, which is a bad thing.

Did you actually try it?
What compilers were you using?
I get the same result regardless of compiler, hardware and OS.

    Reply    Reply to author    Forward  
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.
Discussion subject changed to "A Super KISS" by io_x
io_x  
View profile  
 More options Nov 4, 12:40 am
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: "io_x" <a...@b.c.invalid>
Date: Wed, 4 Nov 2009 01:40:08 +0100
Local: Wed, Nov 4 2009 12:40 am
Subject: Re: A Super KISS

"geo" <gmarsag...@gmail.com> ha scritto nel messaggio
news:a14dbdd8-cce7-4038-ad6b-a9f34b9c3cc4@f16g2000yqm.googlegroups.com...

the asm version

; compile with
; nasmw -fobj   rndasm.asm
; bcc32   -v  rndasm.obj
section _DATA use32 public class=DATA
global _main
extern _printf

indx  dd     41790
carry dd    362436
xcng  dd   1236789
xs    dd 521288629
IIIIIIxIIdIIn db "     x=%d." , 13, 10, 0
IDoesIxII872412446IIn db "Does x=-872412446?" , 13, 10, 0
section _BSS use32 public class=BSS

vettoreQ resd 41792

section _TEXT use32 public class=CODE

          align   4
initialize:
          push    esi
          push    edi
          push    ebp
          mov     ecx,  41790
          mov     esi,  vettoreQ
          mov     edi,  [xcng]
          mov     ebp,  [xs]
.0:       mov     eax,  69609
          mul     edi
          add     eax,  123
          xchg    eax,  edi
          mov     eax,  ebp
          shl     eax,  13
          xor     ebp,  eax
          mov     eax,  ebp
          shr     eax,  17
          xor     ebp,  eax
          mov     eax,  ebp
          shr     eax,  5
          xor     ebp,  eax
          lea     eax,  [ebp+edi]
          mov     [esi],  eax
          add     esi,  4
          loop    .0
          mov     [xcng],  edi
          mov     [xs],  ebp
          pop     ebp
          pop     edi
          pop     esi
          ret

          align   4
rnd:
          push    esi
          push    edi
          mov     ecx,  [indx]
          mov     esi,  vettoreQ
          cmp     ecx,  41790
          jne     .1
          push    esi
.0:       mov     eax,  7010176
          mul     dword[esi]
          add     eax,  [carry]
          adc     edx,  0
          mov     [carry],  edx
          not     eax
          mov     dword[esi],  eax
          add     esi,  4
          loop    .0
          pop     esi
.1:       mov     edi,  [esi+4*ecx]
          inc     ecx
          mov     [indx],  ecx
          mov     eax,  69609
          mov     ecx,  [xcng]
          mul     ecx
          add     eax,  123
          mov     [xcng],  eax
          add     edi,  eax
          mov     edx,  [xs]
          mov     eax,  edx
          shl     eax,  13
          xor     edx,  eax
          mov     eax,  edx
          shr     eax,  17
          xor     edx,  eax
          mov     eax,  edx
          shr     eax,  5
          xor     edx,  eax
          mov     [xs],  edx
          add     edi,  edx
          xchg    edi,  eax
          pop     edi
          pop     esi
          ret

          align   4
_main:
          pushad
          call    initialize
          mov     esi,  0
.0:       call    rnd
          inc     esi
          cmp     esi,  1000000000
          jb      .0
          mov     edi,  eax
          push    eax
          push    IIIIIIxIIdIIn
          call    _printf
          add     esp,  8
          push    IDoesIxII872412446IIn
          call    _printf
          add     esp,  4
          popad
          xor     eax,  eax
          ret


    Reply    Reply to author    Forward  
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.
Discussion subject changed to "RNGs: A Super KISS" by io_x
io_x  
View profile  
 More options Nov 4, 12:40 am
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: "io_x" <a...@b.c.invalid>
Date: Wed, 4 Nov 2009 01:40:24 +0100
Local: Wed, Nov 4 2009 12:40 am
Subject: Re: RNGs: A Super KISS

"Tom St Denis" <t...@iahu.ca> ha scritto nel messaggio
news:4fd3c8bf-e45b-4359-ac50-f54298b14770@d21g2000yqn.googlegroups.com...
On Nov 3, 10:46 am, geo <gmarsag...@gmail.com> wrote:

> int refill( )
> { int i; unsigned long long t;
> for(i=0;i<41790;i++) { t=7010176LL*Q[i]+carry; carry=(t>>32); Q[i]=~
> (t);}
> indx=1; return (Q[0]);
> }

Not to nitpick but your C code could use some work.  First off, some
indentation please?  Second, returning a unsigned long long as "int"
is not very portable.

<where is written that he return long long int like int??
<Q is "static unsigned long Q[41790]"
<he return only "unsigned long" like "int"
<the error could be here "Q[i]=~(t)" because in the left side is long
<the other side is long long

Part of the good thing of PRNGs is that they're reproduceable.
Ideally over different platforms.  You should truncate the return
value if you want it as "int" or change the return type.  As it stands
now this will produce different results on my x86-32 and 64 boxes for
the same seed, which is a bad thing.

Tom


    Reply    Reply to author    Forward  
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.
David  
View profile  
 More options Nov 4, 5:18 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: David <david.astgt...@gmail.com>
Date: Wed, 4 Nov 2009 09:18:14 -0800 (PST)
Local: Wed, Nov 4 2009 5:18 pm
Subject: Re: RNGs: A Super KISS
On an x86-64 machine using GCC version 4.3.3 (Ubuntu 4.3.3-5ubuntu4),
both the C code and C++ code fail for me.
I get:
     x=505478909.
Does x=-872412446?

Changing the unsigned long's to unsigned int's fixed the problem.
And it does matter: before the change, the generator failed a variety
of tests (really odd assortment, though: parking lot, 2dsphere,
3dsphere, squeeze, and sums).

David


    Reply    Reply to author    Forward  
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.
James Waldby  
View profile  
 More options Nov 4, 6:09 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: James Waldby <n...@no.no>
Date: Wed, 04 Nov 2009 12:09:22 -0600
Local: Wed, Nov 4 2009 6:09 pm
Subject: Re: RNGs: A Super KISS

On Wed, 04 Nov 2009 09:18:14 -0800, David wrote:
> On an x86-64 machine using GCC version 4.3.3 (Ubuntu 4.3.3-5ubuntu4),
> both the C code and C++ code fail for me. I get:
>      x=505478909.
> Does x=-872412446?

That result is like what I mentioned in my posts yesterday;  
505478909. == 0x1e20fefd, which is the low 32 bits
of 2904265093743181565. == 0x284e05b71e20fefd .

> Changing the unsigned long's to unsigned int's fixed the problem. And it
> does matter: before the change, the generator failed a variety of tests
> (really odd assortment, though: parking lot, 2dsphere, 3dsphere,
> squeeze, and sums).

...

--
jiw


    Reply    Reply to author    Forward  
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.
user923005  
View profile  
 More options Nov 4, 9:26 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt
From: user923005 <dcor...@connx.com>
Date: Wed, 4 Nov 2009 13:26:33 -0800 (PST)
Local: Wed, Nov 4 2009 9:26 pm
Subject: Re: RNGs: A Super KISS
On Nov 4, 9:18 am, David <david.astgt...@gmail.com> wrote:

> On an x86-64 machine using GCC version 4.3.3 (Ubuntu 4.3.3-5ubuntu4),
> both the C code and C++ code fail for me.
> I get:
>      x=505478909.
> Does x=-872412446?

> Changing the unsigned long's to unsigned int's fixed the problem.
> And it does matter: before the change, the generator failed a variety
> of tests (really odd assortment, though: parking lot, 2dsphere,
> 3dsphere, squeeze, and sums).

OK, makes sense.  The RNG must assume 32 bit longs.

    Reply    Reply to author    Forward  
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.
user923005  
View profile  
 More options Nov 4, 9:31 pm
Newsgroups: sci.math, comp.lang.c, sci.crypt, comp.lang.c++
From: user923005 <dcor...@connx.com>
Date: Wed, 4 Nov 2009 13:31:20 -0800 (PST)
Local: Wed, Nov 4 2009 9:31 pm
Subject: Re: RNGs: A Super KISS
On Nov 4, 1:26 pm, user923005 <dcor...@connx.com> wrote:

> On Nov 4, 9:18 am, David <david.astgt...@gmail.com> wrote:

> > On an x86-64 machine using GCC version 4.3.3 (Ubuntu 4.3.3-5ubuntu4),
> > both the C code and C++ code fail for me.
> > I get:
> >      x=505478909.
> > Does x=-872412446?

> > Changing the unsigned long's to unsigned int's fixed the problem.
> > And it does matter: before the change, the generator failed a variety
> > of tests (really odd assortment, though: parking lot, 2dsphere,
> > 3dsphere, squeeze, and sums).

> OK, makes sense.  The RNG must assume 32 bit longs.

Modified C++ code:

#include <iostream>

class SuperKiss {

private:
    unsigned int  Q[41790];
    unsigned int  indx;
    unsigned int  carry;
    unsigned int  xcng;
    unsigned int  xs;

    int refill ()
    {
        int i;
        unsigned long long t;
        for (i = 0; i < 41790; i++)
        {
            t = 7010176LL * Q[i] + carry;
            carry = (t >> 32);
            Q[i] =(unsigned int) ~(t);
        }
        indx = 1;
        return (Q[0]);
    }

public:
    // Constructor:
    SuperKiss()
    {
        indx  = 41790;
        carry = 362436;
        xcng  = 1236789;
        xs    = 521288629;
        unsigned i;
        for (i = 0; i < 41790; i++)
            Q[i] = (xcng = 69609 * xcng + 123) +
                   (xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^=
xs >> 5);
    }

    // Collect next random number:
    unsigned int SKRand() {
        return (indx < 41790 ? Q[indx++] : refill ()) +
               (xcng = 69609 * xcng + 123) +
               (xs ^= xs << 13, xs ^= (unsigned) xs >> 17, xs ^= xs >>
5);
    }

};

int
main ()
{
    unsigned int i;
    int x=0;
    SuperKiss sk;
    for (i = 0; i < 1000000000; i++)
        x = sk.SKRand();
    std::cout << "   x = " << x << std::endl << "Does x=-872412446?"
<< std::endl;
    return 0;

}

/* Possible output:
   x = -872412446
Does x=-872412446?
*/

    Reply    Reply to author    Forward  
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.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google