You are on page 1of 18

Random-Variate Generation

Need for Random-Variates


We, usually, model uncertainty and unpredictability with
statistical distributions
Thereby, in order to run the simulation models involving
uncertainty, we need to get samples from these statistical
distributions
Here, we assume that the distributions (type and
parameters) are already specified
ARENA comes with ready functions to sample from
specified distributions.
It is still useful to know how it is done
We will generate the variates always using random
numbers, whose generation is discussed previously
Inverse Transform Technique --
Exponential Distribution
To generate samples from exponential distribution we use the inverse
transform technique


Step 1. Compute the cdf of the desired random variable X, F(x).
Step 2. Find the inverse of F(x) function


Step 4. Generate uniform random variables R
1
, R
2
, R
3
, and compute
the desired random variates by

<
>
=

0 , 0
0 ,
) (
x
x e
x f
x

<
>
=

0 , 0
0 , 1
) (
x
x e
x F
x
) 1 ln(
1
) ( 1 ) (
1
y y F x e y x F y
x
= = = =

) 1 ln(
1
) (
1
i i i
R R F X = =

Inverse Transform Technique --


Exponential Distribution
Inverse Transform Technique --
Exponential Distribution
Example: Generate 200 variates X
i
with distribution
exp(= 1)






Check: Does the random variable X
1
have the desired
distribution?
Proof?
Can you prove that the numbers you have
generated are indeed samples from an
exponential distribution?
Other Distributions
Uniform Distribution [ UN(a,b)] (X = a + (b-a)R)
Does it really work?
Weibull Distribution



Derive the transformation
Triangular .
The moral is if we can find a closed-form inverse of the
cdf for a distribution we can use this method to get
samples from that distribution
( )

<
>
=

0 , 0
0 ,
) (
1
x
x e x
x f
x
|
o
|
|
o
|
Continuous Functions without a
Closed-Form Inverse
Some distributions do not have a closed form expression
for their cdf or its inverse (normal, gamma, beta, )
What can be done then?
Approximate the inverse cdf
For the standard normal distribution:


This approximation gives at least one-decimal place
accuracy in the range [0.0012499, 0.9986501]
1975 . 0
) 1 (
) (
135 . 0 135 . 0
1
R R
R F X

~ =

Discrete Distributions
An Empirical Discrete Distribution
p(0) = P(X=0) = 0.50
p(1) = P(X=1) = 0.30
p(2) = P(X=2) = 0.20





Can we apply the inverse transform technique?

s
< s
< s
<
=
x
x
x
x
x F
2 , 0 . 1
2 1 , 8 . 0
1 0 , 5 . 0
0 , 0
) (
Discrete Distributions

Let x
0
= -, and x
1
, x
2
, , x
n
, be the ordered probability
mass points for the random variable X
Let R be a random number

i i i
x X x F R x F if = s <

) ( ) (
1
Discrete Distributions
A Discrete Uniform Distribution
] 1 , 1 [
, 1
, 1 ,
1 , 0
) (
., . . , 2 , 1 ,
1
) (
e

s
+ < s
<
=
= =
k
x k
i f or i x i
k
i
x
x F
k x
k
x p
) (
1
kR roundup X or
i X
k
i
R
k
i
if
=
= s <

Discrete Distributions
The Geometric Distribution



Some algebraic manipulation and




( )
( ) . . . , 2 , 1 , 0 , 1 1 ) (
. . . , 2 , 1 , 0 , 1 ) (
1
= =
= =
+
x p x F
x p p x p
x
x
( )
( )
|
|
.
|

\
|

= 1
1 ln
1 ln
p
R
roundup X
Acceptance-Rejection Technique
Useful particularly when inverse cdf does not exist in
closed form, a.k.a. thinning
Illustration: To generate random variates, X ~ U(1/4, 1)





R does not have the desired distribution, but R
conditioned (R) on the event {R > } does.
Efficiency: Depends heavily on the ability to minimize
the number of rejections.
Procedures:
Step 1. Generate R ~ U[0,1]
Step 2a. If R >= , accept X=R.
Step 2b. If R < , reject R, return
to Step 1
Generate R
Condition
Output R
yes
no
Acceptance-Rejection Technique
Poisson Distribution


N can be interpreted as number of arrivals from a
Poisson arrival process during one unit of time
Then time between the arrivals in the process are
exponentially distributed with rate o

. . . , 2 , 1 , 0 ,
!
) ( ) ( = = = =

n
n
e
n N P n p
n
o
o

+
= =
< s =
1
1 1
1
n
i
i
n
i
i
A A n N
Acceptance-Rejection Technique
Step 1. Set n = 0, and P = 1
Step 2. Generate a random number R
n+1
and let P = P. R
n+1

Step 3. If P < e
-o
, then accept N = n. Otherwise, reject
current n, increase n by one, and return to step 2
How many random numbers will be used on the average to
generate one Poisson variate?
[ [

+
=

=
+
= =
+
= =
> >
< s < s
1
1 1
1
1 1
1
1 1
ln
1
1 ln
1
1
n
i
i
n
i
i
n
i
i
n
i
i
n
i
i
n
i
i
R e R
R R A A
o
o o
Direct Transformations
dx e x
t
x
2
2
2
1
) (

}

= u
t
Consider two normal variables Z
1
and Z
2








( )
( )
2 2 2
1 2
1
1
2
1 1 2
2 1 2
~ with twodegrees of freedom
(Exponential with parameter 2)
tan ~ [0, 2 ]
2ln
2ln cos 2
2ln sin 2
B Z Z Chi square
Z
Uniform
Z
B R
Z R R
Z R R
u t
t
t

= +
| |
=
|
\ .
=
=
=
Direct Transformation
Approach for normal(,o
2
):
Generate Z
i
~ N(0,1)




Approach for lognormal(,o
2
):
Generate X ~ N(,o
2
)
Y
i
= e
X
i

X
i
= + o Z
i
Convolution Method
Erlang Distribution
An Erlang-K random variable X with parameters (K, u) (1/u is the
mean, K is the stage number) can be obtained by summing K
independent exponential random variables each having mean
1/(K u)
|
|
.
|

\
|
= =
=
[

= =
=
K
i
i i
K
i
K
i
i
R
K
R
K
X
X X
1 1
1
ln
1
ln
1
u u

You might also like