Opened 13 years ago

Closed 10 years ago

#599 closed Bugs (fixed)

uniform_01 copies engine instead of using a reference

Reported by: uhoreg Owned by: jmaurer
Milestone: Component: random
Version: None Severity:
Keywords: Cc:


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&) as its argument, and the _rng member should
be a base_type&.  (Indeed, the documentation at
says that the constructor takes a base_type&.)

Change History (3)

comment:1 Changed 12 years ago by jmaurer

Status: assignedclosed
Logged In: YES 
Originator: NO

With the introduction of variate_generator<>, the random number engines have been redesigned some years ago. Unfortunately, boost/random/variate_generator.hpp now relies on uniform_01<> 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.

comment:2 Changed 11 years ago by azzie@…

Resolution: Fixed
Status: closedreopened

I still haven't found this warning in 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?

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).

comment:3 Changed 10 years ago by Steven Watanabe

Resolution: fixed
Status: reopenedclosed

(In [51337]) Convert uniform_01 to the current distribution interface, dispatching on the first template paramter to retain backwards compatibility. Fixes #599. Fixes #1544. Fixes #2679

Note: See TracTickets for help on using tickets.