Boost logo

Boost Users :

From: Morgan (mkita_at_[hidden])
Date: 2005-01-11 18:18:19


This is my first bug report(ever), so feel free to point out how I could
do a better job of this...

Anyways I have found a bug with the mersenne_twister random number
generator class, where results when calling for a random number vary
between codewarrior 9.0 and gcc 3.4.1 with boost 1.31.0.

A simple example is shown below:

#include <boost/random/mersenne_twister.hpp> // for mt11213b

typedef boost::mt11213b base_generator_type;

class foo
{
 public:
  foo(const base_generator_type gen):m_gen(gen)
  {}

  ~foo(void) {}

  rand_type operator() ( void )
  {
   const float x = m_gen();

   return x;
  }

 private:

  base_generator_type m_gen;
}

int main(void)
{

 base_generator_type gen( (uint32_t) 2000); seed is not important

 foo f(gen);

 cout << "Random result is " << f() << endl;
}

The resulting numbers will be different between codewarrior 9.0 running
on windows and gcc 3.4.1 running on Suse linux 7.3.(Hope that is enough
info).

I tracked the cause of the bug down to class initialization. In the case
of CW9.0, the compiler when constructing a foo, will use a
mersenne_twister copy ctor when initializing m_gen, while in the case of
gcc 3.4.1 it will choose the following in the .hpp file

  template<class Generator>
  explicit mersenne_twister(Generator & gen) { seed(gen); }

therefore using the provided generator as a seed to the new generator
rather than just copying its state, even though no template parameter is
provided.

Anyways I will leave it up to the more informed to decide which is more
desirable/proper; however, this is a fairly nasty bug at the moment as


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net