Boost logo

Boost Users :

From: Kevin Martin (kev82_at_[hidden])
Date: 2008-07-21 11:57:36


On 21 Jul 2008, at 16:47, Olivier Tournaire wrote:

> I am currently using boost::random, and I wonder how it is possible
> to get uniform random numbers on a union of two intervalls.
> For instance, I would like to generate uniform_real numbers in the
> intervall [-a;-b]U[b;a].

Generate a number uniformally in the interval [0,2*(a-b)]. If it is
smaller than a-b then add b to it. If it is larger than a-b then
multiply it by -1.

I think any function which picks the two intervals with equal
probability should work.

Thanks,
Kevin Martin


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