Docsity

Random Number Generation - Discrete Systems Simulation | EMSE 273, Study notes of Systems Engineering

Toggle sidebar
bg1
EMSE 273- Discrete System Simulation
Lecture Notes by J.R. van Dorp 1
Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7
7. RANDOM NUMBER - GENERATION
7.1 Properties of Random Numbers
A sequence of random numbers , must have two important statisticalVVßáß
"8
properties: and Uniformity Independence
Each VVµYÒ!ß"Ó
3 should be an independent realization (or sample) from a
variable:
x
01
f(x)
1
x
01
f(x)
1
f(x)f(x)
1
IÐVÑ œ B.B œ B l œ
'!##
"""
#"
!
Z +<ÐVÑ œ B ÒIÐVÑÓ œ B l Ò Ó œ œ
'!$#$%"#
"##$"#
"""""
!
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Random Number Generation - Discrete Systems Simulation | EMSE 273 and more Study notes Systems Engineering in PDF only on Docsity!

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

7. RANDOM NUMBER - GENERATION

7.1 Properties of Random Numbers A sequence of random numbers

,^

must have two important statistical

V

V ß á ß "^

8

properties:

and

Uniformity

Independence

Each

V

V μ Y Ò!ß "Ó

3 should be an independent realization (or sample) from a

variable:

x

0

1

f ( x ) 1

x

0

1

f ( x ) f ( 1 x ) f ( x ) 1

IÐVÑ œ

B.B œ

B l

œ

#^

"^

"^

"

"

!

Z +<ÐVÑ œ

B

 ÒIÐVÑÓ

œ

B l

 Ò Ó

œ

œ

$^

#^

$^

%^

"#

"^

#^

#^

$ "

"^

"^

"^

"^

"

!

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

Consequences of Uniformity and Independence Properties:

  1. If the interval

is divided into

subinterval of equal length, the expected

Ò!ß "Ó

number of observations in each interval is

where

is the total number of

R Î8ß

R

observations

  1. The probability of observing a value in a particular interval is independent of

the previous values drawn. 7.2 Generation of Pseudo-Random Numbers "Pseudo" means false, so false random numbers are being generated. If themethod is known the numbers cannot be truly random. The goal of anygeneration scheme is to

the real properties of a uniform distribution and

"imitate"

independence as closely as possible.

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Usually, pseudo-random numbers are generated by a computer as part of thesimulation. Numerous methods are available. In selecting a routine, there are anumber of important considerations.1. The routine should be fast2. The routine should be platform independent and portable between differentSource: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

programming languages.

  1. The routine should have a sufficiently long cycle (much longer than the

required number of samples).

  1. The random numbers should be replicable. Usefull for debugging and variance

reduction techniques.

  1. Most importantly, the routine should closely approximate the ideal statistical

properties.

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

Inventing techniques that seem to generate random

number is easy; inventing techniques that reallyproduce sequences that appear to independent,

uniformly distributed is incredibly difficult.

7.3 Techniques for Generating Random Numbers

Þ

The linear congruential method is most widely known. Will also report anextension that yield sequences with a longer period. 7.3.1. Linear Congruential Method Generates a sequence

using

\ ß \ ß \ ß á

"^

#^

$

\

œ Ð+\  -Ñ 79. 7

Ð(Þ"Ñ

3"

3

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp \ Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

œ #( ! \

œ Ð"( † #(  %$Ñ 79. "!! œ &!# 79. "!! œ # " V

œ

œ !Þ!#

"^

"!!

\

œ Ð"( † #  %$Ñ 79. "!! œ (( 79. "!! œ ((

V

œ

œ !Þ((

#^

( "!!

ã etc. Of primary importance is uniformity and statistical independence. Of secondary

importance is

and

within the sequence

maximum density

maximum period

V 3 œ "ß #ß á Þ

Note that, the sequence can only take values in:

Ö!ß "Î7ß #Î7ß á ß Ð7  "ÑÎ7ß "×

Thus

is discrete rather than continuous. V

3

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp This is easy to fix by choosing large modulus Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

. Values such as

and

7 œ #

$"

7 œ #

%)

are in common use in generators appearing in many simulation

languages). Maximum Density and Maximum period can be achieved by theproper choice of

,^

,^

and

\

!

•^

For

a power of

, say

, and

, the longest period

is

#^

7 œ #

- Á!

T œ 7 œ #

,^

,

achieved provided

is a relative prime to

(that is the greates common

-^

factor of

and

is

), and

where

is an integer.

-^

"^

  • œ "  % † 5

•^

For

a power of

, say

, and

, the longest period

#^

7 œ #

  • œ!

,

T œ 7Î% œ #

\

,#

!

is achieved provided the seed

is odd and the multiplier

  • œ $  ) † 5

5 œ !ß "ß á

, for some

•^

For

is a prime number and

, the longest period

is

  • œ!

T œ 7  "

achieved provided the multiplier

has the property that the smallest integer

5 œ 7  "

such that

is divisible by

is

5

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

Average

Variance

Average Gap

Over 500 Samples

Empe rical CDF of LCG Ge ne rator ov e r 500 Sample s

1.0000.9000.8000.7000.6000.5000.4000.3000.2000.100 0.

r

CDF

Em perical CDF

Uniform CDF

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

7.3.2. Combined Linear Congruential Method

Random Number Generator of Example 7.4. with a period of

#^

$"

is no longer adequate with current advancements of computing powers. Area ofnew research is deriving generators with longer periods (See, L'Ecuyer [1998]).This research uses the following important result.

If

are independent discrete valued random variables (not

[

ß [

ß á [

3ß"

3ß#

3ß

necesarrily identical distributed), but one of them, say

, is uniformly

[

3ß"

distributed on the integers

, then

!ß á ß 7

"

[ œ

[

79. Ð

 "Ñ

3

3ß

"

(^5) 4œ" 

is uniformly distributed on the integers

!ß á ß 7

 "Þ

"

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Note that the Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

Ð  "Ñ

\

4"

3ß"

coefficient implicitly perform the subtraction

. For

example, if

5 œ #

Ð  "Ñ Ð\

 "Ñ  Ð  "Ñ Ð\

 "Ñ œ

Ð  "Ñ

\

!^

"^

4"

3ß"

3ß#

3ß

4œ"

Maximum possible period for such a generator is:

T œ

Ð

 "Ñ

(^5) # 3œ"

(^5) 5"

which is achieved by the following generator.

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp EXAMPLE 7.5:1. Selected seed Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

Selected seed

\

− Ò"ß #"%(%)$&'#Óß

\

− Ò"ß #"%(%)$$$*)ÓÞ

"!

#ß!

,

2 Evaluate each individual generator

Þ

\

œ Ð%!!"% † \

Ñ 79. #"%(%)$&'$

"ß4"

"ß

\

œ Ð%!

† \

Ñ 79. #"%(%)$$$**

#ß4"

#ß

  1. Set

\

œ Ð\

 \

Ñ 79. #"%(%)$&'#

4"

"ß4"

#ß4"

  1. Return

V

œ

\

\

œ !Þ

4"

#"%(%)$&'$

4

#"%(%)$&'##"%(%)$&'$

4

4"

  1. Set

and go to Step 2.

4 œ 4  "

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

7.4 Tests for Random Numbers

Þ

Desirable Properties: Uniformity and Independence

Uses the Kolmogorov-Smirnic or the Chi-Square Test to

Frequency Test: compare the distribution of the set of numbers to a uniform distribution.2.

Test the runs up and down or the runs above and below the mean

Runs Test: by comparin the actual values to expected values. The Statistics for comparisonis the chi-square test.3.

Test the correlation between numbers and compares the

Autocorrelation Test: sample correlation to the expected correlation of zero.4.

Counts the number of digits that appear between repetitions of a

Gap Test: particular digit and then uses the Kolmogorov Smirnov test to compare with theexpected sized of the gaps.5.

Treat numbers grouped together as a poker hand. Then the hands

Poker Test: obtained are compared to what is expected using the chi-square test.First Entry test for Uniformity. Second through Fifth Entry tests for Independence.

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp 7.4.1. Frequency Tests1. The Kolmogorov-Smirnov Test Test compares a continuous cdf Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

to an emperical cdf

, of the sample of

J ÐBÑ

W

ÐBÑ

R

R

observations. Step 1: Determine Order Statistics

V

Ÿ V

Ÿ á Ÿ V

Ð(Þ$Ñ

Ð"Ñ

Ð#Ñ

ÐR Ñ

Define:

W

ÐBÑ œ

ß 3 œ "ß á ß R  "

!^

B Ÿ VV

Ÿ B  V

"^

B

V

R

Ð"Ñ

(^3) R^

Ð3Ñ

Ð3"Ñ

ÐR Ñ

Ú ÛÜ

Step 2: Compute

via

H œ Q +B

lJ ÐBÑ  W

ÐBÑl

B − Ò  ∞ß ∞Ó

R

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp Step 3: Compute for significant level Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

or

(for

α

œ !Þ"!ß !Þ!&

!Þ!"

R

$&Ñ

H

œ

ß H

œ

ß H

œ

"Þ##

"Þ$'

"Þ'$

R

R

R

!Þ"!

!Þ!&

!Þ!"

È

È

È

Step 4: Test Hypothesis

œ

H Ÿ H

W

ÐBÑ

J ÐBÑ

H  H

W

ÐBÑ

J ÐBÑ

α α

Accept: No Difference between

and

Reject: No Difference between

and

R R

EMSE 273- Discrete System Simulation Lecture Notes by J.R. van Dorp

2. The Chi-square Test The chi-square test uses the sample statistic Source: Discrete Event Simulation by Banks Carson and Nelson Chapter 7

#!

(^8) 3œ"

3

3

3

œ

ÐS  I Ñ

I

where

is the observed number in the

-th class,

is the expected number in

S

I

3

3

the

-th class, and

is the number of classes.

Step 1: Determine Order Statistics

V

Ÿ V

Ÿ á Ÿ V

Ð(Þ$Ñ

Ð"Ñ

Ð#Ñ

ÐR Ñ

Step 2: Divided Range

in

equidistant intervals

, such that

V

 V

Ò+ ß , Ó

ÐR Ñ

Ð"Ñ

3

3

each interval has at least

observations. &

Step 3: Calculate for

3 œ "ß á ß R

S œ R † ÖW

Ð, Ñ  W

Ð+ Ñ×ß I œ R † ÖJ Ð, Ñ  J Ð+ Ñ×

3

R

3

R

3

3

3

3