Tut 2 2020
Tut 2 2020
1
NETW 707: Modeling & Simulation
Assoc. Prof. Tallal El-Shabrawy
Tutorial 2
Random Numbers
Simulation is indicated to estimate the system performance through sampling. In
simulation models, sampling from any probability distribution is based on the use of [0, 1)
random number, since a random number represents the value of a random variable
uniformly distributed on [0, 1). The statistical conditions of these random numbers are
i. All continuous values in the interval [0, 1) are equally likely to occur. i.e., they are
uniformly distributed over the interval [0, 1).
ii. They must be independent and uncorrelated.
Most random number generators use some form of a congruential relationship, such as
Mid-Square Method, Linear congruential generator, the multiplicative generator, and the
mixed generator.
The Linear congruential generator is the most widely used as a built-in random number
function on computer systems.
Mid-Square Method
Start with a four-digit positive integer Z0 and repeat the following steps:
1. Square Z0 to obtain an integer up to eight digits, if necessary, append zeros to the
left to make it exactly eight digits.
2. Take the middle four digits of this eight-digit number as the next four-digit
number Z1.
3. Place a decimal point at the left of Z1 to obtain the first “U(0,1) random number”
U1.
4. Repeat the above three steps to generate required random numbers.
Linear Congruential generator
With this method, we produce a sequence of integers x1 , x2 , x3 ,... between zero
and (m-1) according to the following recursive relation.
Z i 1 a Z i c (mod m), i 0,1, 2 ... (1)
Where:
a is a constant multiplier,
c is the increment, and
m is the modulus ( modulus m are non-negative integers).
The initial starting value of Z 0 is called the seed.
Relation (1) is called mixed type congruential method.
Special cases:
i. If a=1, then (1) becomes
Z i 1 Z i c (mod m)
is called additive type congruential method.
2
NETW 707: Modeling & Simulation
Assoc. Prof. Tallal El-Shabrawy
Tutorial 2
Definition: Let p the period of a sequence, when p equals its maximum, i.e., p=m. We
say that the random number generator has a full period.
Theorem: Full period generator
The LCG has a full period if and only if the following three conditions hold:
i. The only positive integer that (exactly) divides both m and c is 1.
ii. If q is a prime number (divisible by only itself and 1) that divides m, then q divides
(a-1). i.e., a 1(modq), Prime factor q of m.
iii. If 4 divides m, then 4 divides (a-1). i.e., a 1(mod4), If m is a multiple of
4.
3
NETW 707: Modeling & Simulation
Assoc. Prof. Tallal El-Shabrawy
Tutorial 3
Since RNGs are completely deterministic, we need to test them to see if they appear to be
random and IID uniform on [0, 1]. Most computers will have built-in RNGs but unless software
is designed for simulation the RNGs can be extremely poor and may not be adequate to be used to
generate random variates in a stochastic model. It is recommended to test such generators before
usage (or any generator in general) with one of the following tests. There two types of tests:
empirical tests
theoretical tests
In the empirical test the Ui’s produced by the generator themselves are used to check how
good is the generator using any of the statistical tests available.
The theoretical test on the other hand uses the parameters of the generator to assess it
globally without actually generating any random numbers. So this test is not actually a test in the
statistical sense.
2- Divide the range RN- R1 in n equidistant intervals such that each interval has at least 5
observations
3- Calculate
where:
Oi = the number of observations in the ith class
Ei = the expected number in the ith class
n = the number of classes
4- For significant level α, utilize the table of percentage points of the Chi square distribution
with v degrees of freedom to determine
5- If ≤
Accept: “No difference between and F(x)
If >
Reject