Author: Dieter Buerssner
Date: 14:41:52 08/17/02
Go up one level in this thread
On August 17, 2002 at 06:35:16, Andrew Williams wrote:
>I use the Mersenne-Twister random number generator.
I agree, that Mersenne-Twister is a very good generator:
>long long random64() {
> long long rand;
> int r1, r2;
>
> r1 = randomMT();
> r2 = randomMT();
>
> rand = r1;
> rand = rand << 32;
> rand = rand | r2;
>
> return rand;
>}
To me, it seems this is buggy. To show an example with hard coded values instead
of calls to the Mersenne twister:
long long random64() {
long long rand;
int r1, r2;
r1 = 0x12345678;
r2 = 0xffffffff; /* A valid return from Mersenne twister */
rand = r1;
rand = rand << 32;
rand = rand | r2;
/* We exect 0x12345678ffffffff */
return rand;
}
#include <stdio.h>
int main(void)
{
unsigned long long r = random64();
printf("%0LLx\n", r);
return 0;
}
When I start the program, I get
ffffffffffffffff
Perhaps, this late at night, I have overlooked something ...
BTW. Using unsigned types yields the expected result:
unsigned long long random64() {
long long rand;
unsigned long r1, r2; /* why use int, when long is more protable? */
r1 = 0x12345678;
r2 = 0xffffffff; /* A valid return from Mersenne twister */
rand = r1;
rand = rand << 32;
rand = rand | r2;
/* We exect 0x12345678ffffffff */
return rand;
}
Regards,
Dieter
12345678ffffffff
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.