Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2004-12-31 10:51:14

Doug Gregor wrote:
> I'm having a few problems dealing with uniform_real and uniform_01.
> The basic issue is that uniform_real does not always produce values
> between its min and its max.

uniform_real was meant to be used with variate_generate<> only.
Reviewing the language in the ISO C++ TR draft seems to miss
one requirement: That the Engine used as input for uniform_real()
always returns numbers in the range [0..1[, if floating-point numbers
are requested. This is one of the features of variate_generate<>:
it wraps the original Engine so that this is always the case.

Note that the current ISO C++ TR draft already requires
that the input Engine produce numbers of the "correct" type
(floating-point or integer).

> Looking at the source to uniform_real, the problem is obvious:
> result_type operator()(Engine& eng) { return eng() * (_max - _min) +
> _min; }

Yes. Fixed.

> However, uniform_01 is also broken in several ways:

uniform_01, at this time, is just an implementation helper
for variate_generator<> and thus should move to the details
namespace ASAP. Since it's hideously broken for general
use right now, I'm inclined to perform the move without
any deprecation period.

Jens Maurer

Boost list run by bdawes at, gregod at, cpdaniel at, john at