Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

Foundations

UP Mindanao
of Mathematics

SIMULATION
MODELING

GENERATING RANDOM
NUMBERS
February 6, 2014

Prepared
A
presentation
by: LM
of Estaa
Leo Manuel B. Estaa

AMATMath
110 201

Middle-Square Method
The middle-square method was developed in
1946 by Jon Von Neuman, S. Ulm, and N.
Metropolis at Los Alamos Laboratories to simulate
neutron collisions as part of the Manhattan
Project.

The middle-square method works as follows:


1. Start with a four digit number x0, called the
seed.
2. Square it to obtain an eight-digit number
(add a leading zero if necessary).
3. Take the four digits as the next random
number.
Simulation Modeling

AMAT 110

Middle-Square Method
EXAMPLE:
Pick a seed say x0 = 2041.
Generating 9 random numbers in this way
yields:

Continuing the process, a sequence that


appears to be random over the integers 0 to
9999 is obtained.
Simulation Modeling

AMAT 110

Middle-Square Method
What if you wanted to generate random numbers within the interval say 0 to 1?

Simply divide the generated four digit


number with 10000.

What if you wanted generate five-digit random


numbers?
Then start your seed with a five-digit
number and take the middle five-digit
number.

Simulation Modeling

AMAT 110

Linear Congruence Method

The linear congruence method was introduced


by D.H. Lehmer in 1951.
One advantage it has over other methods is that
seeds can be selected that generate patterns
that eventually cycle.

Simulation Modeling

AMAT 110

Linear Congruence Method

Methodology

The method requires the choice of integers: a, b and c.


Given some initial seed, say x0, we generate a sequence by the rule:
xn+1 = (a xn + b)mod(c)
where c is the modulus, a is the multiplier and b is the increment.
The mod(c) in the equation means to obtain the remainder after
dividing the quantity (a xn + b) by c.

Simulation Modeling

AMAT 110

Linear Congruence Method


EXAMPLE:
a = 1, b = 7 and c = 10,
xn+1 = (1 xn + 7)mod(10)
means that xn+1 is the integer remainder upon
dividing xn + 7 by 10.
Thus if xn = 115, xn+1 = remainder(122/10) = 2.

Simulation Modeling

AMAT 110

Linear Congruence Method


Cycling

means that the sequence repeats itself.

Example:
If we set our seed at x0 = 7, we find
x1 = (1 x 7 + 7)mod(10) or 14mod(10), which is
4.
Repeating the same procedure, we obtain the
following sequence: 7, 4, 1, 8, 5, 2, 9, 5, 3, 0,
7, 4, , and the original sequence repeats
again and again.
Simulation Modeling

AMAT 110

Linear Congruence Method

Observe that the methodology produces cycling after 10 numbers that is a sequence of integers between 0 and c -1.
Cycling is guaranteed in at most c random numbers in the random number sequence.
The c can be chosen to be very large and a and b chosen in such a way to obtain a full set of c numbers. Many computers use c = 2 31 for the large value of c.
You can scale the random numbers to obtain a sequence between any limits a and b as required.

Simulation Modeling

AMAT 110

Linear Congruence Method


Problems:

Cycling;
Lack of statistical independence among the
members in the list of random numbers.
The sequence will appear independent if
subjected to certain statistical tests which
can be best addressed in a course in
statistics.

Simulation Modeling

AMAT 110

Linear Congruence Method


Quiz: YP
1.

2.

Use the Middle-Square Method to generate


a. 10 random numbers using x0 = 1009.
b.

20 random numbers using x0 = 765321.

c.

15 random numbers using x0 = 3043

d. Comment the results of each sequence.


Use the Linear Congruence Method to generate
a. 10 random numbers using a=5,b=1 and c=8
b. 15 random numbers using a=1,b=7 and
c=10
c. 20 random numbers using a=5,b=3 and
c=16
d. Comment the results of each sequence.

Simulation Modeling

AMAT 110

You might also like