Search code examples
c++boost-random

Using boost for (pseudo-)random number generator of long double


I'm trying to use boost for random number generation of a long double (on a 64bits machine).

At some point I use

rng = boost::mt19937();

However, compiler argues that on line 88 of boost/random/mersenne_twister.hpp,

x[i] = (1812433253UL * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;

there is an implicit conversion that shortens the 64-bit into a 32-bit value...

I didn't even specified if I want a long double or double... why is he arguing on that? Is because I'm using 64bits OS?

Is there any simple solution to this problem? I need a long double generator... xD

Thanks


Solution

  • The mt19937 is 32bit. It is defined in the boost like

    typedef mersenne_twister_engine<uint32_t,32,624,397,31,0x9908b0df,
    11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253> mt19937;
    

    For 64bit is necessary to use mt19937_64.