Boost logo

Boost Users :

Subject: Re: [Boost-users] [random] infinite loop in uniform_real_distribution
From: Brian Budge (brian.budge_at_[hidden])
Date: 2013-11-25 19:33:20


On Mon, Nov 25, 2013 at 2:53 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> 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;
> }
>

Ah, I see. Nice :) Thanks for suggesting another simple solution.

  Brian


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