You are on page 1of 29

Generation of Random Numbers

and Random Observations


Presented by:
Juanito S. Chan
Random Numbers

• Random numbers are rational


numbers with equal likelihood of
being drawn out whose values
range from zero to one [0 ≤ µi ≤ 1]
Acceptable Methods for Generating
Random Numbers
1. Uniformly distributed (equal probabilities)
2. Statistically independent
3. Reproducible
4. Nonrepeating for any desired length
5. Generation at high rate of speed
6. Requires minimum amount of location space
Alternative Methods of Generating
Sequences of Random Numbers
1. Manual Methods – simplest and least practical
Examples: coin flipping, dice rolling, card
shuffling, roulette the wheels, and drawing
numbers from a box
Advantage: numbers generated are “truly”
random numbers
Disadvantage: impossible to reproduce a
sequence of random numbers generated by
such devices
2. Library tables – numbers are first generated
before recording them in table form
Example: Rand Corporation’s “A Million
Random Digits”
Advantage: reproducibility
Disadvantages: lack of speed and possibility
of using the same “random” data for every
problem
3. Analog Devices
Example: behavior of electric current
Advantages: yield “truly” random numbers and
faster in generation
Disadvantage: non reproducible
4. Digital Computer Methods
Types:
a. External Provision – enter predetermined random numbers
as data and use same for the problem.
Example: Rand Corporation’s random digits entered
through computer magnetic tape
Disadvantage of external provision: slow process, that
is, it can take ten times as long to read one character of
information into a computer as it does to perform an
arithmetic operation of a single character.
b. Internal generation by a random physical process –
involves the use of a special adjunct to a digital
computer that can record the results of same random
process and can reduce these to a sequence of digits.
Example: Record the results through computer random
processes as decay of radioactive material and the
thermal noise in an electric value circuit.
Disadvantages: non-reproducibility and random process
may go out of control and a check on its production of
digits is required.
c. Internal generation by a recurrence relation – involves
the generation of pseudo random numbers by
indefinitely continued transformation of a group of
arbitrarily chosen numbers.
Advantages: No problem as far as input and memory
storage capacity are concerned and reproducible
Disadvantage: sequence of digits generated by purely
deterministic rule is the direct antithesis of a random
sequence.
Internal Generation by a Recurrence
Relation
• Midsquare Method
– Start with an arbitrary seed having k number of
digits (usually even) – represent the first random
number in the sequence by µ0
– The next random number is µ1 selecting by
squaring µ0 and extracting the middle k digits of µ1
– The process is repeated so that µi is taken as
middle k digits of i 1
2
Shortcomings of midsquare method
• Short repeatability
• Whenever zero is generated, all succeeding numbers will be
zero.
Example: x0 = 44
(44)2 = 1936 → x1 = 93
(93)2 = 8649 → x2 = 64
(64)2 = 4096 → x3 = 09
(09)2 = 0081 → x4 = 08
(08)2 = 0064 → x5 = 06
(06)2 = 0036 → x6 = 03
(03)2 = 0009 → x7 = 00
(00)2 = 0000 → x8 = 00
Linear Congruential Method (Lehmar)
 aX  c 
X i 1  aX i  c   i m
 m 
X o  seed
a  constant multiplier
c  increment
m  modulus divisor
where a, c, m  0
am cm
@ largest tr uncated integer resulting from
the division
Example
• Suppose m = 8; a = 5; c = 7; X0 = 4
n Xi 5Xi +7 (5Xi +7)/8 Xi+1
0 4 27 27/8 = 3 + 3/8 27 – 3(8) = 3
1 3 22 22/8 = 2 + 6/8 22 – 2(8) = 6
2 6 37 37/8 = 4 + 5/8 37 – 4(8) = 5
3 5 32 32/8 = 4 + 0/8 32 – 4(8) = 0
4 0 7 7/8 = 0 + 7/8 7 – 0(8) = 7
5 7 42 42/8 = 5 + 2/8 42 – 5(8) = 2
6 2 17 17/8 = 2 + 1/8 17 – 2(8) = 1
7 1 12 12/8 = 1 + 4/8 12 – 1(8) = 4
Observations on Linear Congruential
Method
• Xi+1 for i = 1, 2, 3, ….. is actually the remainder
when aXi + c is divided by m → Xi+1 = (aXi + c)
modulus m
• Xi < m → actually the largest Xi = m – 1
Rules for selecting m, a, and c
• Choice of m. Since the period will always be
less than m, a larger value of m is desirable.
Furthermore, a value of m that will facilitate
the solution of the congruence relation should
be used. In machines that utilize a binary
number representation, a value of 2k – 1,
where k is the word size of the machine, has
proven excellent.
• Choice of a and c. A sequence generated by a
linear congruential scheme has a period of m
if and only if
– c is relatively prime to m
– a – 1 is a multiple of 4 if m is multiple of 4.
Example: c = 1, 3, 5, 7 a = 1, 5, 9, 13
In particular, choices of a = 216 + 5 = 65541 and a =
216 + 3 = 65539 have proven to be successful.
• 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.
Multiplicative Congruential Method
• In this method, c = 0.
• Example: Let a = 2; c = 0; m = 10; X0 = 1
X0 = 1
X1 = (2 x 1) modulus 10 = 2
X2 = (2 x 2) mod 10 = 4
X3 = (2 x 4) mod 10 = 8
X4 = (2 x 8) mod 10 = 6
X5 = (2 x 6) mod 10 = 2
X6 = (2 x 2) mod 10 = 4
X7 = (2 x 4) mod 10 = 8
X8 = (2 x 8) mod 10 = 6
Pseudo Random Number Generator
• This is useful for generating random numbers
that fall in the interval (0, 1).
X i 1  10 p cX i
where a denotes the fractional part of a
p  number of digits in the pseudorand om no.
c  constant multiplier 0  c  1
c  10-p 200 A  B 
where A  any nonnegativ e integer
B  {3, 11, 13, 19, 21, 27, 29, 37, 53, 59, 61,
67, 69, 77, 83, 91}
X 0  10  p k where k is any integer not divisible
by 2 or 5 such that 0  k  10 p
Example of Pseudorandom random
generation
• X0 = 0.33 A = 0 B = 11 p = 2
• c = 10-2 (0 + 11) = 0.11
X0 = 0.33
X1 = (100*(0.11)*(0.33)) = 0.63
X2 = (100*(0.11)*(0.63)) = 0.93
X3 = (100*(0.11)*(0.93)) = 0.23
X4 = (100*(0.11)*(0.23)) = 0.53
X5 = (100*(0.11)*(0.53)) = 0.83
Disadvantage of Pseudorandom
Number Generator
• Slow because of many
multiplication operations are
required to generate the
sequence of random numbers.
IBM Random Numbers
SUBROUTINE RANDU (IX, IY, YFL)
IX = IX * 65539
IF (IY) 5, 6, 6
5 IY = IY + 2147488647 + 1
6 YFL = IY
YFL = YFL * .4656613 E -09
RETURN
END
IBM RANDOM NUMBERS
• IY = resultant integer random number
between 0 and 231 – 1
• YFL = desired random number between 0 and
1
• IX = any number with nine or fewer digits
supplied by the user. Preferable to be odd
number. IX is set to be equal to IY each time
the subroutine is called.
IBM RANDOM NUMBERS
m  231  1
X i 1 
 
X i  216  3
231  1
a  216  3

Example :
38 IX = 937513
71 CALL RANDU (IX, IY, YFL)
IX = IY
Additive Congruential Generator
(Knuth)
Features:
• Requires as its seed, a sequence of n numbers x1,
x2, ……, xn
• Equation Xj = (Xj-1 + Xj-n ) mod m
Advantages:
• Speedy since no multiplication is required.
• Can yield periods greater than m.
Disadvantage:
• Theoretical behavior is not well understood as
the behavior of mixed congruential method.
Example of additive congruential
method
• Let m = 10, X1 = 1, X2 = 2, X3 = 4, X4 = 8, X5 = 6
• X6 = (X5 + X1)mod 10 = (6 + 1) mod 10 = 7
• X7 = (X6 + X2)mod 10 = (7 + 2) mod 10 = 9
• X8 = (X7 + X3)mod 10 = (9 + 4)mod 10 = 3
• X9 = (X8 + X4)mod 10 = (3 + 8)mod 10 = 1
• X10 = (X9 + X5)mod 10 = (1 + 6)mod 10 = 7
• X11 = (X10 + X6)mod 10 = (7 + 7)mod10 = 4
• X12 = (X11 + X7)mod 10 = (4 + 9)mod 10 = 3
• X13 = (X12 + X8)mod 10 = (3 + 3)mod 10 = 6
• X14 = (X13 + X9)mod 10 = (6 + 1)mod 10 = 7
• X15 = (X14 + X10)mod 10 = (7 + 7)mod 10 = 4
• X16 = (X15 + X11)mod 10 = (4 + 4)mod 10 = 8
• X17 = (X16 + X12)mod 10 = (8 + 3)mod 10 = 1
• X18 = (X17 + X13)mod 10 = (1 + 6)mod 10 = 7
• X19 = (X18 + X14)mod 10 = (7 + 7)mod 10 = 4
• X20 = (X19 + X15)mod 10 = (4 + 4)mod 10 = 8
Quadratic Congruential Generator
(Conveyou)
Features:
• m is a power of 2
• Nearly equivalent to midsquare method but
has a longer period.
• Equation: Xi+1 = (Xi (Xi + 1))mod m
• X0 must satisfy the relation X0 mod 4 = 2
Example of Quadratic Congruential
Generator
• X0 = 2 m = 16 2 mod16 = 2
• X1 = [2(3)]mod 16 = 6
• X2 = [6(7)]mod 16 = 10
• X3 = [10(11)]mod 16 = 14
• X4 = [14(15)]mod 16 = 2
• X5 = [2(3)]mod 16 = 6
• X6 = [6(7)]mod 16 = 10
• X7 = [10(11)]mod 16 = 14
• X8 = [14(15)]mod 16 = 2

You might also like