From: James Waldby on
On Tue, 03 Nov 2009 14:39:02 -0600, James Waldby wrote:

> On Tue, 03 Nov 2009 07:46:27 -0800, George Marsaglia wrote: ...
>> 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.
> ...
>> static unsigned long
>> Q[41790],indx=41790,carry=362436,xcng=1236789,xs=521288629;
> ...
>> {unsigned long i,x;
> ...
>> printf(" x=%d.\nDoes x=-872412446?\n",x);
> ...
>> Running this program should produce 10^9 KISSes in some 7-15 seconds.
> ...
>> 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 [...]
>
> 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).

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

--
jiw
From: user923005 on
On Nov 3, 12:39 pm, James Waldby <n...(a)no.no> wrote:
> On Tue, 03 Nov 2009 07:46:27 -0800, George Marsaglia wrote:  ...
> > 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.
> ...
> > static unsigned long Q[41790],indx=41790,carry=362436,xcng=1236789,xs=521288629;
> ...
> > {unsigned long i,x;
> ...
> >  printf("     x=%d.\nDoes x=-872412446?\n",x);
> ...
> > Running this program should produce 10^9 KISSes in some 7-15 seconds.
> ...
> > 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 [...]
>
> 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).
>

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>
From: Dann Corbit on
In article <4fd3c8bf-e45b-4359-ac50-f54298b14770
@d21g2000yqn.googlegroups.com>, tom(a)iahu.ca says...
>
> On Nov 3, 10:46�am, geo <gmarsag...(a)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.
From: io_x on

"Tom St Denis" <tom(a)iahu.ca> ha scritto nel messaggio
news:4fd3c8bf-e45b-4359-ac50-f54298b14770(a)d21g2000yqn.googlegroups.com...
On Nov 3, 10:46 am, geo <gmarsag...(a)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



From: David on
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