Sample Question #172 (applied statistics)

In Monte Carlo simulations, we need to generate a random sample from some distribution. If I give you an arbitrary pdf *f*(*x*), how do you generate such a sample? Describe your methodology in detail using any software package or programming language you’re comfortable with.

### Like this:

Like Loading...

*Related*

ANSWER

There are two general methods for generating iid random variables given a distribution. (Specific short-cut methods exist for some popular distributions.) The more direct method involves finding the inverse transform of the cdf F(x). The idea is that the cdf of any distribution is a Uniform(0,1) distribution. If we can find its inverse function, we can first generate a random number from U(0,1) and use the inverse function to find the corresponding x from the original distribution. If the inverse of a cdf cannot be found easily (either algebraically or numerically), we use the sampler density technique (also known as the accept-reject technique), whereby we find a "simpler" cdf that’s similar to the original cdf and then correcting the generated data by some transform.