Boost C++ Libraries: Ticket #10064: generate_uniform_real may go into infinite loop https://svn.boost.org/trac10/ticket/10064 <p> See uniform_real_distribution.hpp: </p> <p> template&lt;class Engine, class T&gt; T generate_uniform_real( </p> <blockquote> <p> Engine&amp; eng, T min_value, T max_value, boost::mpl::true_ /<strong> is_integral&lt;Engine::result_type&gt; */) </strong></p> </blockquote> <p> { </p> <blockquote> <p> for(;;) { </p> <blockquote> <p> typedef T result_type; typedef typename Engine::result_type base_result; result_type numerator = static_cast&lt;T&gt;(subtract&lt;base_result&gt;()(eng(), (eng.min)())); result_type divisor = static_cast&lt;T&gt;(subtract&lt;base_result&gt;()((eng.max)(), (eng.min)())) + 1; BOOST_ASSERT(divisor &gt; 0); BOOST_ASSERT(numerator &gt;= 0 &amp;&amp; numerator &lt;= divisor); T result = numerator / divisor * (max_value - min_value) + min_value; if(result &lt; max_value) return result; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> Please add a "BOOST_ASSERT(max_value &gt; min_value);". </p> <p> If one declares something like </p> <blockquote> <p> boost::random::mt19937 mt; boost::random::uniform_real_distribution&lt;double&gt; dist(0.0, 0.0); </p> </blockquote> <p> dist(mt) makes generate_uniform_real go into an infinite loop. </p> <p> Thank you and best regards. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10064 Trac 1.4.3 harris.pc@… Thu, 07 Aug 2014 23:42:46 GMT attachment set https://svn.boost.org/trac10/ticket/10064 https://svn.boost.org/trac10/ticket/10064 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">comments_patch.diff</span> </li> </ul> Ticket harris.pc@… Thu, 07 Aug 2014 23:43:39 GMT <link>https://svn.boost.org/trac10/ticket/10064#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10064#comment:1</guid> <description> <p> Hi, </p> <p> I see you have added the asserts, but could you also please adjust the comments? see attached patch, </p> <p> Thanks, Paul </p> </description> <category>Ticket</category> </item> </channel> </rss>