Random Number Generation
by
Prof. Richard B. Goldstein
  1. Uniform
  2. Exponential
  3. Normal
  4. Log-normal
  5. Weibull
  6. Gamma
  7. Beta
  8. Binomial
  9. Geometric
  10. Poisson
Return to: Statistics

Uniform Distribution
f(x) = 1/(b - a) for a <= x <= b

Continuous:
X = a + (b - a)*R

Integers only:
X = [a + (b - a + 1)*R]

a
b
Integers only?



Exponential Distribution
f(x) = (1/a)*e-x/a for x >= 0

X = - a*ln(R)
a


Normal Distribution
f(x) = (2πσ)-0.5e-(x-μ)2/2σ2

x1 = 2*R1 - 1
x2 = 2*R2 - 1
xx = x12 + x22
if xx < 1 then
  Z = x1 * (-2*ln(xx)/xx)0.5
  X = μ + Z * σ
 mean (μ) 
st. dev. (σ)


Log-normal Distribution
f(x) = (2πσ)-0.5e-(x-μ)2/2σ2

Z = N(0,1) from normal distribution
x = eμ + Z * σ
μ
σ


Weibull Distribution
f(x) = αβxβ-1 e-αxβ for x >= 0

x = α(-ln(R))β
alpha (α)
 beta (β)


Gamma Distribution
f(x) = (1/Γ(a))xa - 1e-x for x >= 0

case: 0 < a < 1
  U = R1
  c = (e + a)/e where e=exp(1)
  P = cU
  If P <= 1 then
    x = P1/a
    V = R2
    accept x if V <= e-x
  If P > 1 then
    x = - ln((c - P)/a)
    accept x if x >= 0
case: a = 1
  x = - ln(R)
case: a > 1
  Y = - ln(R1)
  U = R2
  If ln U <= (a - 1)(1 - Y + ln Y) then
    accept x = aY
a


Beta Distribution
f(x) = (1/Β(a, b)))xa - 1(1 - x)b - 1 for 0<=x<=1, a>0, b>0

Y1 = Gamma(a) variate
Y2 = Gamma(b) variate
x = Y1/(Y1 + Y2)
a
b


Binomial Distribution
P(X=x) = (n!/x!(n-x)!)px(1 - p)n - x for 0<=p<=1, n=1,2,3...

Let Xi = 1 if U <= p
otherwise, let Xi = 0

x = X1 + X2 + ... + Xn

note: for large n use normal approx.

p
n


Geometric Distribution
P(X=x) = p(1 - p)x - 1 for 0 < p < 1, n=1,2,3...

1. Let x = 1
2. U=U(0,1)
3. If U > p, let x = x + 1 and go to step 2; otherwise finish
p


Poisson Distribution
P(X=x) = λxe/x! for λ > 0, x = 0, 1, 2, ...

1. Let p = e, s = p, x = 0
2. U=U(0,1)
3. If U > s set x = x + 1, p = pλ/x, s = s + p and go to 2
   Otherwise, finish.

note: for large n use normal approx.

λ



Up to the Top

References: