|
Boost Users : |
Subject: Re: [Boost-users] [random] infinite loop in uniform_real_distribution
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-11-25 17:53:39
AMDG
On 11/25/2013 02:22 PM, Brian Budge wrote:
>
> You can achieve what you want by generating a random number on [-1, 1]
> and multiplying it by the max float. I don't think that there is a
> *general* way to arrive at a uniform distribution of a range greater
> than max float by first generating a random number on [0, 1), so it's
> unlikely that the library can be "fixed" to achieve what you want.
>
It's really quite easy.
if ( max - min == infinity )
{
divisor = 2;
min /= divisor;
max /= divisor;
} else {
divisor = 1;
}
// compute a value in [min, max) as usual
result *= divisor;
> Another method would be to use double precision generation on the max
> float range, and then convert to float.
>
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net