Boost logo

Boost :

From: (noreply_at_[hidden])
Date: 2005-02-02 19:08:26

Bugs item #1115124, was opened at 2005-02-02 16:08
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:

Category: random
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Morgan (toth21)
Assigned to: Jens Maurer (jmaurer)
Summary: Diff in state of mersenne_twister gen between GCC3.41 & CW9

Initial Comment:
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
  foo(const base_generator_type gen):m_gen(gen)

  ~foo(void) {}

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

   return x;


  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 (xp or 2000) and
gcc 3.4.1 running on Suse linux 7.3.(Hope that is enough

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 you can not reproduce
results between these two platforms when using this
random number generator for your random numbers.


You can respond by visiting:

This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at
Boost-bugs mailing list

Boost list run by bdawes at, gregod at, cpdaniel at, john at