Random Variables Generation

advertisement
Random Variables Generation
In this section we will discuss how you can select an appropriate probability
distribution to represent random input for a model. To do this, you must know how to
generate random numbers (i.e. common random numbers that draw from a uniform
distribution between 0 and 1) and need to transfer them somehow into draws from the
input probability distributions you want for your model.
Random Numbers Generation

For simulation, the random numbers generator must have the following desire
properties:
1. It should produce numbers that are random.
2. It should be fast.
3. It should not require much computer storage.
4. It should have a long period before cycling. The object is to select a
generation method that produces all of the random numbers that are
needed before cycling occurs.
5. It should not regenerate; that is not repeating the same number over and
over.
6. It should generate stream of random numbers that can be reproduced. That
is for debugging and testing the response of the simulation program for the
same stream of random numbers.

Methods for random numbers generation:
1. Manually random numbers generation.
2. Random numbers generation by using Tables.
3. Analog Computer random number generation.
4. Digital Computer random number generation.
We here cover only two types of digital computer methods. The first one is
very simple and known as "Mid-Square" method. The second one is wide used
and known as "Congruence Modulo-m" method.
1
1. Mid-Square Method
The following flowchart represents the steps of generation random numbers (RN)
using this method.
Start
Select a seed number (X) with n-digits.
(X1X2.....Xn). X is the initial random
number. n is even
Square X to obtain number (Y) with mdigits. Y1Y2.....Ym= (X1X2.....Xn)2
Use R
as seed
Add zeros to the left of Y to form Z
number with (2n) digits,
Z1Z2.....Z2n= 00.....0 Y1Y2.....Ym
Extract the middle n-digits of Z, which
represent by number R,
R1R2.....Rn= Z(n/2)Z(n/2)+1.....Z(3n/2)
R represents
a RN
Need more
RN
End
2
Example:
1. Calculate the first five random numbers using mid-square method for the
cases:
a- Seed=15,
b- Seed=1920.
Answer:
a. Seed=15
15,
(15)2=225,
(22)2=484,
0225,
then R1=22
0484,
then R2=48
2304,
then R3=30
30,
(48)2=2304,
(30)2=900,
0900,
then R4=90
90,
(90)2=8100,
8100,
then R5=10
22,
48,
b. Seed=1920
1920,
(1920)2=3686400,
(6864)2=47114496,
03686400,
then R1=6864
47114496,
then R2=1144
01308736,
then R3=3087
3087,
(1144)2=1308736,
(3087)2=9529569,
09529569,
then R4=5295
5295,
(5295)2=28037025,
28037025,
then R5=0370
6864,
1144,
3
2. Congruence Modulo-m
In this method, the following recursive equation is used:
Xi+1= a * Xi (mod m)
Where:
Xi: is a previous value or initial (seed) if it is X0
a: is a multiplier.
m: is the modulus.
Xi+1 have a range between 0 and less than m. To modify Xi+1 to Ri+1, which is in
the range 0 to less than 1 then, Ri+1= ( Xi+1) /m.
The following flowchart represents the steps of generation RN using this method.
Start
Select X0 (initial value), m (modulus)
and a (multiplier).
Let: i=0
Xi+1= a * Xi (mod m)
Ri+1= ( Xi+1) /m
i=i+1
Yes
Need more
RN
End
4
Example:
1. Calculate the first five random numbers using "Congruence Modulo-m"
method with X0=3, a=5 and m=32.
Answer:
X1= 5*3 (mod 32) =15,
X2= 5*15 (mod 32) =11,
X3= 5*11 (mod 32) =23,
X4= 5*23 (mod 32) =19,
X5= 5*19 (mod 32) =31,
R1=15/32= 0.46875
R2=11/32= 0.34375
R3=23/32= 0.71875
R4=19/32= 0.59375
R5=31/32= 0.96875
Rules for choosing m, X0, and a:

The modulus (m) is chosen as large as possible to maximize period( i.e. period
is [0, (m-1)]) of RN's, m=2b-1, where b (in bits) is the word length of the computer.

The multiplier (a) be chosen to minimize correlation between RN's and keep
the period large, a=2(b/2) ±3.

The seed (X0) is the initial value, should be positive, odd integer, and X0 < m

Period = m/4, when m, X0, and a are chosen in this way.
Example:
The congruence Modulo-m generator is to be implemented on a computer having a
(12 bits) word length. Determine an appropriate set values for (m, X0, and a), then
calculate the first five RN's and the period.
Answer:
m =212-1= 4095
a=2(6) ±3= 67 or 61, take a=67.
Select X0=129
Xi+1= a * Xi (mod m)
X1= 67*129 (mod 4095) = 453,
R1=453/4095= 0.110622
X2= 67*453 (mod 4095) = 1686,
R2=1686/4095= 0.41172
X3= 67*1686 (mod 4095) = 2397,
R3=2397/4095= 0.58534
X4= 67*2397 (mod 4095) = 894,
R4=894/4095= 0.21831
X5= 67*894 (mod 4095) = 2568,
R5=2568/4095= 0.627106
Period = 4095/4 = 1023
5
6
Download