0% found this document useful (0 votes)
39 views21 pages

Random Number Generation and Tests For Uniformity

The document discusses random number generation and tests for uniformity. It describes the importance of random numbers in simulation and different methods for generating random numbers, including the linear congruential method. The linear congruential method generates random integers using a recurrence formula and these integers are then converted to random decimals between 0 and 1 for use in simulations. Parameters like the seed, multiplier, modulus and increment must be carefully chosen to achieve maximal period and uniformity in the random numbers generated.

Uploaded by

Andrea Onglao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views21 pages

Random Number Generation and Tests For Uniformity

The document discusses random number generation and tests for uniformity. It describes the importance of random numbers in simulation and different methods for generating random numbers, including the linear congruential method. The linear congruential method generates random integers using a recurrence formula and these integers are then converted to random decimals between 0 and 1 for use in simulations. Parameters like the seed, multiplier, modulus and increment must be carefully chosen to achieve maximal period and uniformity in the random numbers generated.

Uploaded by

Andrea Onglao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

RANDOM NUMBER

GENERATION AND TESTS


FOR UNIFORMITY
IE 144
Random Random
Simulation
Number Variate
OBJECTIVES FOR TODAY

•  Importance of random numbers in


Simulation
•  Generate Random Numbers using known
methods
•  Test generated RNs for uniformity
RANDOM NUMBERS

Random integers with two important


statistical properties:
•  uniformity
•  (continuous uniform distribution between 0 and 1)

•  independence
RANDOM NUMBER GENERATORS
(RNG)

•  When numbers are generated using a set


procedure, they are often referred to as
“pseudo-random numbers”.
•  RNG is a computational or physical device
designed to generate a sequence of
numbers that lack any pattern
REQUIREMENTS OF RANDOM NUMBER
GENERATORS

•  Reproducible or replicable
•  Non-repeating for a desired length
•  Generation at high rate of speed
•  Requires minimum amount of location space
•  Portability
METHODS FOR RANDOM NUMBER
GENERATION

Methods covered:
•  Linear Congruential Method
•  Midsquare Method

Others methods(Covered in IE 281)


•  Additive Congruential Method
•  Quadratic Congruential Method
•  Mid-Product Method
•  Constant Multiplier Technique
RANDOM DECIMALS

•  Randomly-generated set of numbers


uniformly distributed from 0 to 1
•  Useful in the generation of random variates
RANDOM DECIMALS

!"#$ !"%$ !"&$ !"'$ !"!$ !"'$ !"&$ !"#$

!"()#$ !"&#)$ !"*!+$ !",(%$ !"#%&$ !")%+$

!"%%+$ !"))+$ !"''+$ !"##+$ !"&&+$ !"**+$

!"#),$ !"%)#$ !",'*$ !"+!%$ !"&%!$ !"'#)$


CONVERTING TO RANDOM NUMBERS

•  RNGs generate integers which will need to be


converted to decimals when used in simulation.

To convert whole number (RI) to decimal (RN):


•  For midsquare method: divide by 10k
•  For congruential methods: divide by m
MODULUS OPERATION: METHODS FOR
COMPUTATION

Modulus (mod) r = Y mod m


1.  Solve Y/m, and get the remainder r
2.  r = Y – !Y/m" * m, where !x" is the greatest
integer function of x (largest truncated
integer resulting from the division). [Used in
C, Pascal, VB, Excel-project]
3.  Divide Y/m, subtract the integer part from the
resulting number, and multiply the fractional
part by m. If the answer has a decimal
component of .9999, round up to the next
higher integer. [Used in calculator]
Modulus operation: methods for
computation

4.  In MS Excel, r = MOD(number, divisor)


[Used in exercises only, not in project]
•  Number is the number (Y) for which you want
to find the remainder.
•  Divisor is the number (m) by which you want
to divide number. If divisor is 0, MOD returns
the #DIV/0! error value.
LINEAR CONGRUENTIAL
METHOD
Lehmer (1951)

! Xi+1 = (aXi + c) mod m,


i = 0, 1, 2,...
! Ri = X i / m

X0 – seed, a – multiplier, m – modulus, c – increment


Mixed Congruential Method [c ! 0]
Multiplicative Congruential Method [c = 0]
LINEAR CONGRUENTIAL
METHOD
Observations:
•  Xi < m. Actually, the largest Xi = m – 1
•  The selection of the values for the parameters
a, c, m, X0 drastically affects the statistical
properties and the cycle length.
•  Therefore maximal period can be achieved by
the proper choice of a, c, m, and x0.
LINEAR CONGRUENTIAL
METHOD
•  Largest Xi = m -1, Xi < m
•  Values selection for the inputs affects the
outcomes
•  Generated numbers need to be converted
into random decimals
LINEAR CONGRUENTIAL
METHOD
•  Choice of m. Since the period will always be less
than or equal to m, a larger value of m is desirable.
Values such as 231 – 1 and 248 are in common use.

•  Choice of a and c. A sequence generated by a LCM


scheme has maximal period iff
•  c is relatively prime to m
•  a – 1 is a multiple of 4 if m is a multiple of 4
•  In particular, choices of a = 216 + 5 = 65541 or a = 216 + 3
= 65539 have proven to be successful.
LINEAR CONGRUENTIAL
METHOD

• Choice of X0. If the period of the sequence is


m, the choice of X0 is immaterial, since the
entire sequence will still be generated.
• If the period of the sequence is < m, then the
choice of X0 is important (similar to
Midsquare example).
LINEAR CONGRUENTIAL
METHOD
Example:
Use the linear congruential method to generate a
sequence of random numbers with x0 = 27, a = 17, c
= 43, and m = 100.
The sequence of xi and subsequent Ri values are computed as follows:

X0 = 27
X1 = (17 x 27 + 43) mod 100 = 502 mod 100 = 2
X2 = (17 x 2 + 43) mod 100 = 77 mod 100 = 77
X3 = (17 x 77 + 43) mod 100 = 1352 mod 100 = 52

Convert to decimals by dividing by m.


R1 = X1/m = 2/100 = 0.02
R2 = X2/m = 77/100 = 0.77
R3 = X3/m = 52/100 = 0.52
PERIODS USING VARIOUS SEEDS

"  Using the multiplicative congruential method,


with a = 13, m = 26 = 64 (and c = 0)

i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Xi 1 13 41 21 17 29 57 37 33 45 9 53 49 61 25

Xi 2 26 18 42 34 58 50 10 2

Xi 3 39 59 63 51 23 43 47 35 7 27 31 19 55 11

Xi 4 52 36 20 4
RANDOM DECIMAL STREAM

i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Xi 1 13 41 21 17 29 57 37 33 45 9 53 49 61 25

Ri
/ - 0.20 0.64 0.33 0.27 0.45 0.89 0.58 0.52 0.70 0.14 0.83 0.77 0.95 0.39
= Xi
64

Always remember Xo is not part of the random number/


decimal stream!

You might also like