[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Re: KISS4691, a potentially top-ranked RNG.

robin

4/28/2011 1:15:00 AM

"Uno" <merrilljensen@q.com> wrote in message news:8bfh28Fve1U1@mid.individual.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.
|
| $ 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);
| }

| So, what is all this? In particular, is there something special about
| the value of 3.7 billion?

No, nothing special at all.
The purpose of the exercise is just to confirm that after generating
1000000000 random numbers, you get the same answer as George does.


81 Answers

e p chandler

4/28/2011 11:42:00 AM

0



"robin" wrote in message

| So, what is all this? In particular, is there something special about
| the value of 3.7 billion?

>No, nothing special at all.
>The purpose of the exercise is just to confirm that after generating
>1000000000 random numbers, you get the same answer as George does.

Alas, I think you are making some strong assumptions about the state of
computing in the hereafter.

Gib Bogle

4/29/2011 12:55:00 AM

0

On 4/28/2011 11:42 PM, e p chandler wrote:
>
>
> "robin" wrote in message
>
> | So, what is all this? In particular, is there something special about
> | the value of 3.7 billion?
>
>> No, nothing special at all.
>> The purpose of the exercise is just to confirm that after generating
>> 1000000000 random numbers, you get the same answer as George does.
>
> Alas, I think you are making some strong assumptions about the state of
> computing in the hereafter.
>

George lives on in his code.

David Bernier

4/29/2011 1:51:00 AM

0

e p chandler wrote:
>
>
> "robin" wrote in message
>
> | So, what is all this? In particular, is there something special about
> | the value of 3.7 billion?
>
>> No, nothing special at all.
>> The purpose of the exercise is just to confirm that after generating
>> 1000000000 random numbers, you get the same answer as George does.
>
> Alas, I think you are making some strong assumptions about the state of
> computing in the hereafter.
>

All we have now are George Marsaglia's posts and writings.
I know there's now a move on the way to 64-bit processors,
which I take to mean the x86_64 or AMD64 design/instruction set.

In any case, with an executable compiled with a C compiler,
there's the function sizeof, which might be useful
in some cases at run time.

For example, one could add to main() in C :

printf("the size of an unsigned long in bytes is %d\n", sizeof(unsigned long));

There's also the Itanium architecture and others, and even with a known
processor, some compiler flags affect the number of bytes for
some data types, such as "long double" with the -m64 flag
on Fujitsu SPARC IV with Sun Solaris (--> 16 byte long
doubles with the -m64 flag).

AFAIK, sizeof(unsigned long) can be relied upon to give the size
in 8-bit bytes of a C "unsigned long".

Perhaps some documentation of language, machine, compiler, compiler
options examples where KISS4691 works as per the Marsaglia
specs could be helpful as a reference ...

David Bernier

--
The MegaPenny Project | One Trillion Pennies:
<http://www.kokogiak.com/megapenny/thirte...

Ian Collins

4/29/2011 2:09:00 AM

0

On 04/29/11 01:50 PM, David Bernier wrote:
> e p chandler wrote:
>>
>>
>> "robin" wrote in message
>>
>> | So, what is all this? In particular, is there something special about
>> | the value of 3.7 billion?
>>
>>> No, nothing special at all.
>>> The purpose of the exercise is just to confirm that after generating
>>> 1000000000 random numbers, you get the same answer as George does.
>>
>> Alas, I think you are making some strong assumptions about the state of
>> computing in the hereafter.
>>
>
> All we have now are George Marsaglia's posts and writings.
> I know there's now a move on the way to 64-bit processors,
> which I take to mean the x86_64 or AMD64 design/instruction set.

The move happened several years ago (at least on the desktop and server).

> In any case, with an executable compiled with a C compiler,
> there's the function sizeof, which might be useful
> in some cases at run time.

Being pedantic, sizeof is a compile time operator when used with
integral types.

> For example, one could add to main() in C :
>
> printf("the size of an unsigned long in bytes is %d\n", sizeof(unsigned long));

Given the code as written, assert(sizeof(unsigned long) == 4) would be
more use.

> There's also the Itanium architecture and others, and even with a known
> processor, some compiler flags affect the number of bytes for
> some data types, such as "long double" with the -m64 flag
> on Fujitsu SPARC IV with Sun Solaris (--> 16 byte long
> doubles with the -m64 flag).
>
> AFAIK, sizeof(unsigned long) can be relied upon to give the size
> in 8-bit bytes of a C "unsigned long".

sizeof(unsigned long) is by definition the size in (not necessarily 8
bit) bytes of an unsigned long.

> Perhaps some documentation of language, machine, compiler, compiler
> options examples where KISS4691 works as per the Marsaglia
> specs could be helpful as a reference ...

I suggested long ago the code be updated to use fixed width types, thus
removing any ambiguities.

--
Ian Collins

glen herrmannsfeldt

4/29/2011 2:34:00 AM

0

In comp.lang.fortran David Bernier <david250@videotron.ca> wrote:

(snip)
> All we have now are George Marsaglia's posts and writings.
> I know there's now a move on the way to 64-bit processors,
> which I take to mean the x86_64 or AMD64 design/instruction set.

I have an actual Itanium system, but not so many people do.

> In any case, with an executable compiled with a C compiler,
> there's the function sizeof, which might be useful
> in some cases at run time.

Well, sizeof is a compile time constant, but, yes, you can
use the value at run time.

(snip)
> AFAIK, sizeof(unsigned long) can be relied upon to give the size
> in 8-bit bytes of a C "unsigned long".

No. You need CHAR_BIT to tell how many bits are in a char.
It has been known to get to 64 on word addressed 64 bit machines.
It must be at least 8, but can be more.

-- glen

Eric Sosman

4/29/2011 3:01:00 AM

0

On 4/28/2011 10:09 PM, Ian Collins wrote:
> On 04/29/11 01:50 PM, David Bernier wrote:
>> [...]
>> All we have now are George Marsaglia's posts and writings.
>> I know there's now a move on the way to 64-bit processors,
>> which I take to mean the x86_64 or AMD64 design/instruction set.
>
> The move happened several years ago (at least on the desktop and server).

... for suitable values of "several." DEC's first Alpha CPU's
shipped in 1992, and are now old enough to vote.

>> In any case, with an executable compiled with a C compiler,
>> there's the function sizeof, which might be useful
>> in some cases at run time.
>
> Being pedantic, sizeof is a compile time operator when used with
> integral types.

It's an operator, always. It's evaluable at compile time for
any operand, integral or not, except a variable-length array (whose
element count is not determined until run time).

--
Eric Sosman
esosman@ieee-dot-org.invalid

Ian Collins

4/29/2011 3:09:00 AM

0

On 04/29/11 03:01 PM, Eric Sosman wrote:
> On 4/28/2011 10:09 PM, Ian Collins wrote:
>> On 04/29/11 01:50 PM, David Bernier wrote:
>
>>> In any case, with an executable compiled with a C compiler,
>>> there's the function sizeof, which might be useful
>>> in some cases at run time.
>>
>> Being pedantic, sizeof is a compile time operator when used with
>> integral types.
>
> It's an operator, always. It's evaluable at compile time for
> any operand, integral or not, except a variable-length array (whose
> element count is not determined until run time).

The context was integral types, I didn't want to venture anywhere near
VLAs on a cross-post!

--
Ian Collins

David Bernier

4/29/2011 3:16:00 AM

0

Ian Collins wrote:
> On 04/29/11 01:50 PM, David Bernier wrote:
[...]

>> All we have now are George Marsaglia's posts and writings.
>> I know there's now a move on the way to 64-bit processors,
>> which I take to mean the x86_64 or AMD64 design/instruction set.
>
> The move happened several years ago (at least on the desktop and server).
>
>> In any case, with an executable compiled with a C compiler,
>> there's the function sizeof, which might be useful
>> in some cases at run time.
>
> Being pedantic, sizeof is a compile time operator when used with
> integral types.
>
>> For example, one could add to main() in C :
>>
>> printf("the size of an unsigned long in bytes is %d\n",
>> sizeof(unsigned long));
>
> Given the code as written, assert(sizeof(unsigned long) == 4) would be
> more use.
>
>> There's also the Itanium architecture and others, and even with a known
>> processor, some compiler flags affect the number of bytes for
>> some data types, such as "long double" with the -m64 flag
>> on Fujitsu SPARC IV with Sun Solaris (--> 16 byte long
>> doubles with the -m64 flag).
>>
>> AFAIK, sizeof(unsigned long) can be relied upon to give the size
>> in 8-bit bytes of a C "unsigned long".
>
> sizeof(unsigned long) is by definition the size in (not necessarily 8
> bit) bytes of an unsigned long.
>
>> Perhaps some documentation of language, machine, compiler, compiler
>> options examples where KISS4691 works as per the Marsaglia
>> specs could be helpful as a reference ...
>
> I suggested long ago the code be updated to use fixed width types, thus
> removing any ambiguities.

I'm sorry about the inaccuracies and falsehoods in my post.
I support your suggestion, perhaps also adding comments.
I'm the wrong person to update the code, but I would be
willing to test updated C code.

David Bernier

nmm1

4/29/2011 6:15:00 AM

0

In article <ipd9oo$kug$1@dont-email.me>,
Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
>On 4/28/2011 10:09 PM, Ian Collins wrote:
>
>>> In any case, with an executable compiled with a C compiler,
>>> there's the function sizeof, which might be useful
>>> in some cases at run time.
>>
>> Being pedantic, sizeof is a compile time operator when used with
>> integral types.
>
> It's an operator, always. It's evaluable at compile time for
>any operand, integral or not, except a variable-length array (whose
>element count is not determined until run time).

It's not just evaluable at compile time, it is evaluated using
only the type and not the value of the expression. C99 6.5.3.4
paragraph 2.


Regards,
Nick Maclaren.

Uno

4/29/2011 7:04:00 AM

0

On 04/28/2011 08:34 PM, glen herrmannsfeldt wrote:
> In comp.lang.fortran David Bernier<david250@videotron.ca> wrote:
>
> (snip)
>> All we have now are George Marsaglia's posts and writings.
>> I know there's now a move on the way to 64-bit processors,
>> which I take to mean the x86_64 or AMD64 design/instruction set.
>
> I have an actual Itanium system, but not so many people do.
>
>> In any case, with an executable compiled with a C compiler,
>> there's the function sizeof, which might be useful
>> in some cases at run time.
>
> Well, sizeof is a compile time constant, but, yes, you can
> use the value at run time.
>
> (snip)
>> AFAIK, sizeof(unsigned long) can be relied upon to give the size
>> in 8-bit bytes of a C "unsigned long".
>
> No. You need CHAR_BIT to tell how many bits are in a char.
> It has been known to get to 64 on word addressed 64 bit machines.
> It must be at least 8, but can be more.
>
> -- glen

I'm dealing with this same issue in my real life, as my algebraist uncle
seems to have early-onset alzheimer's. So he has his demonstrable
achievements in science and the last few years where he embarrassed himself.

George's C was atrocious at the end. I'd like to let that die.

A kiss is a kiss; it's simple, effective, and not improved by
redefinition when you've lost your marbles.
--
Uno