Boost logo

Boost :

Subject: Re: [boost] [Random]Random value from range
From: Topher Cooper (topher_at_[hidden])
Date: 2010-01-03 19:46:20


On Jan 3, 2010, at 1:59 PM, Steven Watanabe wrote:

>>
>> I have few question related to random library:
>> 1. Is it possibility to write function which will generate numbers from range [min, max] or (min, max)
>>
>
> (min, max) can be handled by rejection from [min, max).
> [min, max] is a bit trickier. Either way, you'll have to implement
> it yourself.

[min, max] isn't that much trickier. It can be handled by rejection from [min, max+ε). In fact, for floating types, the float_next function from the boost math toolkit will provide an ε that doesn't require rejection. The float_prior function allows (min, max) to be done without rejection. Equivalent things can be done for any numeric type with finite precision (including discrete numeric types). Indefinite precision, though, will generally require rejection. An ε very much smaller than max-min will rarely take the rejection path.

Topher Cooper


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk