Boost C++ Libraries: Ticket #351: Diff in state of mersenne_twister gen between GCC3.41 & CW9 https://svn.boost.org/trac10/ticket/351 <pre class="wiki">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 &lt;boost/random/mersenne_twister.hpp&gt; //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 &lt;&lt; "Random result is " &lt;&lt; f() &lt;&lt; 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 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&lt;class Generator&gt; explicit mersenne_twister(Generator &amp; 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. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/351 Trac 1.4.3 jmaurer Mon, 11 Apr 2005 09:28:29 GMT <link>https://svn.boost.org/trac10/ticket/351#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/351#comment:1</guid> <description> <pre class="wiki">Logged In: YES user_id=53943 Thank you for the bug report. Unless there is a typo, this constructor appears to always require a copy of "gen"? foo(const base_generator_type gen) If you want to avoid binding to the Generator&amp; constructor and use the copy constructor instead, you should make sure to convert "gen" to an rvalue (e.g., by using a static_cast&lt;const base_generator_type&gt;(...)) before initializing m_gen. (untested idea). </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>jmaurer</dc:creator> <pubDate>Mon, 11 Apr 2005 09:41:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/351#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/351#comment:2</guid> <description> <pre class="wiki">Logged In: YES user_id=53943 Independent of the boost.random implications, it worries me that two compilers choose two different overloads. That Should Not Happen (tm). Could you try to come up with a short example not depending on any libraries that shows the difference so that Metrowerks and GCC can have a look at it who is right? If you do it in the next 2 days, I can discuss it with the compiler authors here at the ISO C++ meeting. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>jmaurer</dc:creator> <pubDate>Mon, 11 Apr 2005 11:12:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/351#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/351#comment:3</guid> <description> <pre class="wiki">Logged In: YES user_id=53943 See issue 4.40 in the C++ committee's library TR issue list. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Sat, 06 Jun 2009 19:41:40 GMT</pubDate> <title>status, resolution changed https://svn.boost.org/trac10/ticket/351#comment:4 https://svn.boost.org/trac10/ticket/351#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/53699" title="Fix overload resolution for generator constructors/seed. Fixes #351. ...">[53699]</a>) Fix overload resolution for generator constructors/seed. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/351" title="#351: Bugs: Diff in state of mersenne_twister gen between GCC3.41 &amp; CW9 (closed: fixed)">#351</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2424" title="#2424: Bugs: unsigned int causes error in seed() without static_cast (closed: fixed)">#2424</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2887" title="#2887: Bugs: mersenne_twister generated copy ctor overloaded by a template ctor (closed: fixed)">#2887</a> </p> Ticket