Opened 17 years ago
Closed 14 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: |
Description
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 http://www.boost.org/libs/random/random-distributions.html#uniform_01 says that the constructor takes a base_type&.)
Change History (3)
comment:2 by , 15 years ago
Resolution: | Fixed |
---|---|
Status: | closed → reopened |
I still haven't found this warning in http://www.boost.org/libs/random/random-distributions.html#uniform_01 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).
Note:
See TracTickets
for help on using tickets.