Upload
xaraenielledizon
View
216
Download
0
Embed Size (px)
Citation preview
8/3/2019 Modesim Report
http://slidepdf.com/reader/full/modesim-report 1/4
STI College San Fernando Modeling and Simulation
Generating Random Numbers and Variables Page 1 of 4
GENERATING RANDOM NUMBERS
WHAT ARE RANDOM NUMBERS?
Random numbers are a necessary basic ingredient in the simulation of almost all discrete systems.
Most computer languages have a subroutine, object, or function that will generate a random number.Similarly simulation languages generate random numbers that are used to generate event limes and other
random variables.
It is impossible to produce an arbitrarily long string of random digits and prove it is random. Strangely,
it is also very difficult for humans to produce a string of random digits, and computer programs can be written
which, on average, actually predict some of the digits humans will write down based on previous ones.
Intuitively, we can list a number of criteria that a sequence of numbers must fulfill to pass as a random
number sequence:
y unpredictability,
y independence,
y without pattern.
These criteria appear to be the minimum request for an algorithm to produce random numbers. More
precisely we can formulate:
y uniform distribution,
y uncorrelated,
y passes every test of randomness,
y large period before the sequence repeats,
y sequence repeatable and possibility to vary starting values,
y fast algorithm.
PROPERTIES OF RANDOM NUMBERS
Two important statistical properties:
y Uniformity
y Independence
PSEUDORANDOM NUMBERS
Pseudo means false, so false random numbers are being generated. The goal of any generation scheme is
to produce a sequence of numbers between zero(0) and one(1) which simulates, or initiates, the ideal
properties of uniform distribution and independence as closely as possible.
8/3/2019 Modesim Report
http://slidepdf.com/reader/full/modesim-report 2/4
STI College San Fernando Modeling and Simulation
Generating Random Numbers and Variables Page 2 of 4
When generating pseudo-random numbers, certain problems or errors can occur. These errors, or
departures from ideal randomness, are all related to the properties stated previously. Some examples
include the following:
1. The generated numbers may not be uniformly distributed.
2. The generated numbers may be discrete - valued instead continuous valued
3. The mean of the generated numbers may be too high or too low.
4. The variance of the generated numbers may be too high or low
5. There may be dependence. The following are examples:
(a) Autocorrelation between numbers.
(b) Numbers successively higher or lower than adjacent numbers.
(c) Several numbers above the mean followed by several numbers below the mean.
Usually, random numbers are generated by a digital computer as part of the simulation. Numerous
methods can be used to generate the values. In selecting among these methods, or routines, there are a
number of important considerations.
y Fast
y Portable to different computers
y Have sufficiently long cycle.
y Replicable.
y Closely approximate the ideal statistical properties of uniformity and independences.
TECHNIQUES FOR GENERATING RANDOM NUMBERS
y Linear Congruential Method (LCM)
y Combined Linear Congruential Generators (CLCG)
y Random-Number Streams
Linear Congruential Method (LCM)
The linear congruential method, initially proposed by Lehmer [1951], produces a sequence of integers,
X 1, X2,... between zero and m 1 according to the following recursive relationship:
Xi+1 = (a Xi + c) mod m, i = 0,1, 2,...
multiplier modulusincrement
8/3/2019 Modesim Report
http://slidepdf.com/reader/full/modesim-report 3/4
STI College San Fernando Modeling and Simulation
Generating Random Numbers and Variables Page 3 of 4
The initial value X0 is called the seed, a is called the constant multiplier, c is the increment, and m
is the modulus.
The selection of the values for a, c, m, and X 0 drastically affects the statistical properties and the cycle
length.
If c 0, the form is called the mixed congruential method . When c = 0, the form is known as the
multiplicative congruential method. The selection of the values for a, c , m and X0 drastically affects the
statistical properties and the cycle length.
The random integers are being generated [0, m-1], and to convert the integers to random numbers:
X
Ri = ---- , i=1,2,3
m
Example 1:
Use the linear congruential method to generate a sequence of random numbers with X 0 = 27, a = 17, c= 43, and m = 100. Here, the integer values generated will all be between zero and 99 because of
the value of the modulus. These random integers should appear to be uniformly distributed the integers
zero to 99.Random numbers between zero and 1 can be generated by:
Ri = Xi / m, i=1,2,3.
The sequence of Xi and subsequent Ri values is computed as follows:
X0 = 27
X1 = (17.
27 + 43) mod 100 = 502 mod 100 = 2 R1 = 2 100 = 0.02
X 2 = (17 2 + 43) mod 100 = 77 mod 100 = 77
R2 = 77 100 = 0.77
X3 = (1777+ 43) mod 100 = 1352 mod 100 = 52
R3 = 52 100 = 0.52
Example 2:
Find the sequence of random numbers given a = 13, c = 0, m = 31, X0 = 1.
X0 = 1
X1 = (13 * 1 + 0) mod 31 = 13 mod 31 = 13
X2 = (13 * 13 + 0) mod 31 = 169 mod 31 = 14
X3 = (13 * 14 + 0) mod 31 = 182 mod 31 = 27
X4 = (13 * 27 + 0) mod 31 = 351 mod 31 = 10
X5 = (13 * 10 + 0) mod 31 = 130 mod 31 = 6
X6 = (13 * 6 + 0) mod 31 = 78 mod 31 = 16
8/3/2019 Modesim Report
http://slidepdf.com/reader/full/modesim-report 4/4
STI College San Fernando Modeling and Simulation
Generating Random Numbers and Variables Page 4 of 4
X7 = (13 * 16 + 0) mod 31 = 208 mod 31 = 22
X8 = (13 * 22 + 0) mod 31 = 286 mod 31 = 7
X9 = (13 * 7 + 0) mod 31 = 91 mod 31 = 29
X10 = (13 * 29 + 0) mod 31 = 377 mod 31 = 5
X11 = (13 * 5 + 0) mod 31 = 65 mod 31 = 3
The sequence begins with: 1, 13, 14, 27, 10, 6, 16, 22, 7, 29, 5, 3,
What's the next value? Well, it looks pretty unpredictable, but you've been initiated. So you can
compute. The first 30 terms in the sequence are a permutation of the integers from 1 to 30 and then the
sequence repeats itself. It has a period equal to m - 1.
If a pseudorandom integer sequence with values between 0 and m is scaled by dividing by m, the result
is floating-point numbers uniformly distributed in the interval [0 , 1]. Our simple example begins with:
0.0323 , 0.4194 , 0.4516 , 0.8710 , 0.3226 , 0.1935 , 0.5161 , .
There are only a finite number of values, 30 in this case. The smallest value is 1 / 31 and the largest is30 / 31.
Seatwork:
Use the linear congruential method to generate a sequence of random numbers with X 0 = 9, a = 5, c =
11, and m = 16. Find the list of random numbers that will be generated by the given values before an
occurrence of any random number in the list will occur and determine the pseudorandom integer
sequence with values between 0 and m. Show your solution.