A small note on Using Mathematica 6 to generate random variables that are distributed with specific  probability density

by Nasser Abbasi 8/30/076

The problem : We want to generate a set of random variables such that they fit a specific probability distribution. Examples are shown how to do this using Mathematica 6

The method is simple. We Wrap the specific probability distribution function with the function RandomReal or RandomInterger. Use histogram to plot the frequency distribution of the resulting random numbers. Below are 3 examples to illustrate the method.

example 1 : Generate random numbers which are distributed normally with zero mean and variance of 1. Generate 1000 random numbers and display histogram

Needs["Histograms`"]
t=Table[RandomReal[NormalDistribution[0,1]],{i,1000}];
Histogram[t,PlotLabel->"frequency of random numbers distributed normally",AxesLabel->{"x","frequency"}]

example 2 : Generate random numbers which are distributed exponentially with parameter λ=1. Generate 1000 random numbers and display histogram

t=Table[RandomReal[ExponentialDistribution[1]],{i,1000}];
Histogram[t,PlotLabel->"frequency of random numbers distributed exponentially",AxesLabel->{"x","frequency"}]

example 3 : Generate random numbers which are distributed with Gamma Distribution with shape parameter 2 and scaleparameter 5. Generate 1000 random numbers and display histogram

t=Table[RandomReal[GammaDistribution[2,5]],{i,1000}];
Histogram[t,PlotLabel->"frequency of random numbers distributed Gamma",AxesLabel->{"x","frequency"}]