Author: Ricardo Gibert
Date: 00:29:02 08/17/02
Go up one level in this thread
On August 17, 2002 at 01:05:30, Russell Reagan wrote:
>On August 17, 2002 at 00:51:59, Will Singleton wrote:
>
>>I don't have my source code with me now, but I remember that OR'ing the two
>>32-bit values will give very bad results. There must be lots of examples of
>>64-bit rand generation in various sources out there.
>
>In Gerbil, Bruce does:
>
>// "rand()" produces 15-bit values (0..32767). I want 64 bits.
If this is Bruce's comment, then he is not getting what he intended. I don't see
how he could make this mistake. I assume this is your comment. Yes?
>
>static U64 U64Rand(void)
>{
> return (U64)rand() ^ ((U64)rand() << 15) ^ ((U64)rand() << 30);
>}
>
>Russell
He appears to be concatenating three 15 bit values to produce a 45 bit one
rather than a 64 bit one.
If you want 64 bits, you need to make at least 2 more calls to rand() shifted by
45 and 49.
Also, BM is relying on the lower order bits being random which notoriously can
be quite non-random. If you want 64 bits, better is to XOR 8 calls to rand().
Something like the following:
return ((U64)rand() >> 7) ^ ((U64)rand << 1) ^ ((U64)rand() << 9) ^ ((U64)rand()
<< 17) ^ ((U64)rand() << 25) ^ ((U64)rand() << 33) ^ ((U64)rand() << 41) ^
((U64)rand() << 49);
The above is untested.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.