Boost logo

Boost Users :

From: Stephen Nuchia (snuchia_at_[hidden])
Date: 2008-07-21 12:14:16


If b is small compared to a, generate U[-a,a] and reject values in
(-b,b) -- that is, generate a new value when that happens. This is the
general solution to the problem of generating a random variate from an
oddball distribution: you generate from a distribution that dominates
yours and reject values you don't want. When the PDF of your desired
distribution lies between zero and the envelope distribution you need
another random variate to act as a surrogate: if U[0,envelope-value(x)]
< [my-funky-dist-value(x)] we keep the first variate x, else we generate
a new pair.

> For instance, I would like to generate uniform_real numbers in the
> intervall [-a;-b]U[b;a].

The previous answer is an example of a less general but often more
efficient approach: cut up another distribution and paste it back
together to make up yours. These approaches can be combines: paste up
something close and use surrogate screening to fine-tune.

See any good book on simulation.

-swn


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