Boost C++ Libraries: Ticket #599: uniform_01 copies engine instead of using a reference https://svn.boost.org/trac10/ticket/599 <pre class="wiki">In the uniform_01 class, the constructor takes a base_type (i.e. the random number generator) as its argument, and the _rng member is just a base_type. This results in uniform_01 copying the random number generator, along with its state. Thus if one creates several uniform_01 objects (e.g. one at the beginning of each of several functions), they will all return the same random numbers. The constructor should take a reference (i.e. base_type&amp;) as its argument, and the _rng member should be a base_type&amp;. (Indeed, the documentation at http://www.boost.org/libs/random/random-distributions.html#uniform_01 says that the constructor takes a base_type&amp;.) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/599 Trac 1.4.3 jmaurer Thu, 26 Apr 2007 20:16:49 GMT status changed https://svn.boost.org/trac10/ticket/599#comment:1 https://svn.boost.org/trac10/ticket/599#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=53943 Originator: NO With the introduction of variate_generator&lt;&gt;, the random number engines have been redesigned some years ago. Unfortunately, boost/random/variate_generator.hpp now relies on uniform_01&lt;&gt; to take a value (as opposed to a reference). Since I don't have time to fix the infrastructure properly, I've adjusted the documentation for uniform_01 in the CVS to reality, with a big warning hint. If you want to have a [0,1) generator, use uniform_real with appropriate parameters instead. </pre> Ticket azzie@… Fri, 16 Nov 2007 20:43:04 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/599#comment:2 https://svn.boost.org/trac10/ticket/599#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">Fixed</span> </li> </ul> <p> I still haven't found this warning in <a href="http://www.boost.org/libs/random/random-distributions.html#uniform_01">http://www.boost.org/libs/random/random-distributions.html#uniform_01</a> and encountered the same problem. Please make clear that drawing a number from uniform_01 will NOT change the state of the passed generator. And why to pass the generator as a non-const reference if it is not being changed? </p> <p> I suggest making the constructor argument (the reference to the generator) of uniform_01 const and pointing the users to uniform_real which works as expected (changes the state of the generator after drawing a number). </p> Ticket Steven Watanabe Thu, 19 Feb 2009 23:27:42 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/599#comment:3 https://svn.boost.org/trac10/ticket/599#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/51337" title="Convert uniform_01 to the current distribution interface, dispatching ...">[51337]</a>) Convert uniform_01 to the current distribution interface, dispatching on the first template paramter to retain backwards compatibility. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/599" title="#599: Bugs: uniform_01 copies engine instead of using a reference (closed: fixed)">#599</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1544" title="#1544: Bugs: uniform_01 w/ref template param causes ref to ref error (closed: fixed)">#1544</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2679" title="#2679: Patches: boost::uniform_01 constructor (closed: fixed)">#2679</a> </p> Ticket