Boost C++ Libraries: Ticket #1856: minstd_rand returning different values in 1.35.0 than in 1.34.1 https://svn.boost.org/trac10/ticket/1856 <p> After moving from boost 1.34.1 to 1.35.0 I have noticed that the sequence of values returned by the minstd_rand generator has changed. This sample code (included in the attachment) generates different values with 1.35.0 than it did with 1.34.x and 1.33.x: </p> <pre class="wiki"> typedef boost::minstd_rand rng_type; typedef boost::uniform_int&lt;&gt; distrib_type; typedef boost::variate_generator&lt;rng_type &amp;,distrib_type&gt; source_type; rng_type generator(42u); unsigned int seeds[] = {12,23,42}; distrib_type dist(0,INT_MAX); source_type randomSource(generator,dist); for(unsigned int i=0;i&lt;3;++i){ generator.seed(seeds[i]); std::cerr &lt;&lt; seeds[i]; for(unsigned int j=0;j&lt;5;++j){ unsigned int bit = randomSource(); std::cerr&lt;&lt;" "&lt;&lt;bit%1024; } std::cerr&lt;&lt;std::endl; } </pre><p> Output with v1.35.0: </p> <pre class="wiki">12 691 854 1010 690 696 23 444 337 394 1000 751 42 404 8 37 977 972 </pre><p> and with v1.34.1: </p> <pre class="wiki">12 691 844 854 975 292 23 214 852 444 337 394 42 883 404 943 348 8 </pre><p> If I use the mt19937 generator instead of minstd_rand, the sequences are the same across versions. In the event it matters, I'm using g++ v4.1.3 on an Ubuntu Linux system. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1856 Trac 1.4.3 Greg Landrum <greg.landrum@…> Thu, 24 Apr 2008 05:01:30 GMT attachment set https://svn.boost.org/trac10/ticket/1856 https://svn.boost.org/trac10/ticket/1856 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">getvals.cpp</span> </li> </ul> <p> Sample code to demostrate the problem </p> Ticket Steven Watanabe Sun, 22 Feb 2009 23:36:20 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1856#comment:1 https://svn.boost.org/trac10/ticket/1856#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The values returned by minstd_rand are the same for both versions. The difference is in uniform_int. </p> <p> uniform_int didn't handle signed/unsigned issues correctly in 1.33.1. Debugging this test case with 1.33.1 shows that during the second iteration (which prints 854 or 844), for the comparison on uniform_int.hpp line 97 </p> <pre class="wiki"> if(result &lt;= _range) </pre><p> result is 9bad7746 and _range is 7fffffff. Since both arguments are signed, the comparison returns true, which is incorrect. </p> <p> So, I modified the test case to print out the actual values returned by uniform_int, and some of them are indeed negative. </p> <p> The current behavior is correct, so I'm marking this as invalid. </p> Ticket