next up previous
Next: About this document ... Up: Basic Probability Theory for Previous: Pseudo Random Number Generator

Subsections

Non-uniform random numbers

In simulations, you frequently need to generate random number following a distributions other than uniform distributions. In previous exercises, you have already created a rather simple way to draw a random number from the binominal distribution and geometric distribution (remember the coin flipping functions in the homeworks?).

Here I briefly discuss about approaches to create non-uniform random numbers from uniform PRNG.

In reality, I generally use pre-made functions from a library called GNU Scientific Library (GSL).

transformation

Easy when inverse function of cumulative distribution function can be obtained. Image expBoth

e.g., To create a random number y from exponential distribution, draw a unifrom PRN z [0,1), and use the following transformation.

\begin{displaymath}y = - \frac{ln(z)}{\theta} \end{displaymath}

rejection method

Sometimes, you know the probability density/mass function, but cumulative distribution function is difficult to calculate.
Image rejection

Random numbers with GSL

Life is much easier if you know how to use GSL since you don't have to reinvent the wheels. GNU Scientific Library (GSL) is a collection of numerical routines for scientific computing. It's an open source project, and it can be compiled for many platforms (e.g., linux, Mac OS-X, Windows with Cygwin). You may need to install GSL before you can use it (it's usually not installed by default). Here I briefly show how to use the uniform and non-uniform random number generators implemented in GSL. There are many other useful functions, so take a look at the manual. Two sections of manual is relevant for our purpose (PRNGs and Distributions).

There are many more distributions in GSL, and you can use them in the same way as the example above.

Exercises


next up previous
Next: About this document ... Up: Basic Probability Theory for Previous: Pseudo Random Number Generator
Naoki Takebayashi 2008-03-27