Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Random keys and hamming distance

Author: Dieter Buerssner

Date: 14:29:58 08/17/02

Go up one level in this thread


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 my experience, most sources are for 32 bit numbers. And example, how Or can
go bad, by the programmers fault would be (note the similarity to Andrew's
code):

long long r64(void)
{
  long r1, r2;

  r1 = r32();
  r2 = r32();
  /* negative r1 will be casted to a negative long long,
     with many leading one bits */
  return ((long long)r1 | ((long long)r2 << 32);
}

Using unsigned types, will avoid problems.

Regards,
Dieter





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.