mercredi 6 décembre 2017

PRNG MTRand mt.seed() not working as intended (?)

In a simulation project where I need different PRNG with common random numbers (reproducability) I am using the Mersenne Twister implementation by Jasper Bedaux (http://ift.tt/1ix0Rn3). Now, the following loop should, in my understanding, produce a unique random number associated to the integer (i.e. the different instances should yield the same random numbers if initialised with the same seed):

#include <iostream>
#include "mtrand.cpp"

int main()
{
  MTRand tester_sh;
  MTRand tester_se;
  std::cout << std::fixed;
  std::cout << "This is a simple test program.\n";
  for (int sh = 1; sh < 3; sh++) {
    for (int se = 1; se < 3; se++) {   
      tester_sh.seed( sh );
      tester_se.seed( se );
      std::cout << "\n" << sh << "\t" << tester_sh() << "\t" << se << "\t" << tester_se() ;
    }
  }  
  return 0;
}

The output I do get, however is:

Output test program

Neither are the random numbers the same, nor does the "resetting" work for the individual generator.

As I am not a programmer, I am more than puzzled and do not know what I should do.

If important, I am compiling the model with cygwin64\bin\x86_64-w64-mingw32-g++.exe and the options -g -Wall -lm -std=gnu++14 -o %Name%.exe %Name%%Ext%, using a current version of cygwin on windows 7, 64bit.

Any help is welcome!




Aucun commentaire:

Enregistrer un commentaire