jeudi 6 juillet 2017

Why am I getting numbers larger than 1000 when I %1000 a number generated by 64 bit mersene twister engine?

I'm trying to generate a zobrist key for transposition tables in my chess engine. Here's how I'm generating the 64 bit numbers, as show here: How to generate 64 bit random numbers?

typedef unsigned long long  U64;

std::random_device rd;

std::mt19937_64 mt(rd());

std::uniform_int_distribution<U64> dist(std::llround(std::pow(2,61)), 
std::llround(std::pow(2,62)));

rand function:

U64 ZobristH::random64()
{
    U64 ranUI = dist(mt);
    return ranUI;
}

In order to try and make sure i'm generating random enough numbers I'm using a test distribution function I found online that looks like this (will later input data into excel and look at distribution):

int sampleSize = 2000;

int distArray[sampleSize];
int t = 0;
while (t < 10)
{
   for (int i = 0; i < 10000; i++)
   {
       distArray[(int)(random64() % (sampleSize / 2))]++;
   }
   t++;
}
for (int i = 0; i < sampleSize; i++)
{
    std::cout << distArray[i] << ", ";
}

the results I'm getting look a little something like this:

 416763345, 417123246, 7913280, 7914356, 417726722, 417726718, 19, 83886102, 
 77332499, 14

Are these the decimal representation of binary numbers below 1000? Or am I doing something completely wrong?




Aucun commentaire:

Enregistrer un commentaire