0% found this document useful (0 votes)
16 views

Basics of Modelling and Simulation

Random numbers can be generated using a congruential generator algorithm that takes a seed number and generates a series of random-looking digits. Pseudorandom number generators use deterministic algorithms to produce numbers that pass statistical tests for randomness. In BASIC, the RND function generates pseudorandom numbers between 0 and 1, which can be converted to other ranges by multiplying, taking the integer part, and adding or subtracting values. A good random number generator produces uniformly distributed numbers quickly without much memory in a long, non-repeating period.

Uploaded by

Lj Villanueva
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Basics of Modelling and Simulation

Random numbers can be generated using a congruential generator algorithm that takes a seed number and generates a series of random-looking digits. Pseudorandom number generators use deterministic algorithms to produce numbers that pass statistical tests for randomness. In BASIC, the RND function generates pseudorandom numbers between 0 and 1, which can be converted to other ranges by multiplying, taking the integer part, and adding or subtracting values. A good random number generator produces uniformly distributed numbers quickly without much memory in a long, non-repeating period.

Uploaded by

Lj Villanueva
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

UNIT 2

Basics of Modelling
and Simulation
RANDOM
NUMBER
RANDOM NUMBER
Random Number can be defined as numbers that show no consistent pattern, with
each number in a series and are neither affected in any way by the preceding number,
nor predictable from it.
One way to get random digits is to simply start with an arbitrary number with a
specified number of digits, for example 4 digits.

1ST NUMBER – SEED

SEED X CONSTANT NUMBER OF THE SAME NUMBER = DESIRED NUMBER OF DIGITS


IS TAKEN OFF THE RIGHT END OF PRODUCT

THE RESULT BECOME A NEW SEED.

AND REPEAT THE PROCESS.

The result is a series of digits that appear randomly distributed as though generated
by throwing a die or spinning a wheel. This type of algorithm is called a congruential
generator.
RANDOM NUMBER
Generating a random number series from a single seed works fine with most
simulations that rely upon generating random events under the control of
probabilities (Monte Carlo simulations). However, although the sequence of
numbers generated from a given seed is randomly distributed, it is always the
same series of numbers for the same seed. Thus, a computer poker game that
simply used a given seed would always generate the same hands for each player.
One way to do this is to read the time (and perhaps date) from the computer‘s
system clock and generate a seed based on that value. Another common
technique is to use the interval between the user‘s keystrokes (in milliseconds).
The so-called true random number generators extract random numbers from
physical phenomena such as a radioactive source or even atmospheric noise as
detected by a radio receiver.
PSEUDORANDOM
NUMBER
GENERATION
Pseudorandom number generation
Pseudorandom numbers are generated by deterministic algorithms. They are
"random" in the sense that, on average, they pass statistical tests regarding
their distribution and correlation. They differ from true random numbers in that
they are generated by an algorithm, rather than a truly random process.
What we usually do is to take for instance ten pieces of papers and number
them 0,1,2,3,4,5,6,7,8, and 9 , fold and place them in a box. Shake the box and
thoroughly mix the slips of paper. Select a slip; then record the number that is
on it. Replace the slip and repeat this procedure over and over. The resultant
record of digits is a realized sequence of random numbers. Assuming you
thoroughly mix the slips before every draw, the nth digit of the sequence has an
equal or uniform chance of being any of the digits 0, 1, 2,3,4,5,6,7,8, 9
irrespective of all the preceding digits in the recorded sequence.
RANDOM
NUMBERS IN
COMPUTER
Random numbers in computer
The RAND Corporation using specially designed electronic equipment, to
perform the experiment, actually did generate a table of a million random
digits. The table can be obtained on tape, so that blocks of the numbers can
be read into the memory of a high- speed computer, as they are needed.

Experts in computer science have devised mathematical processes for


generating digits that yield sequences satisfying many of the statistical
properties of a truly random process. To illustrate, if you examine a long
sequence of digits produced by deterministic formulas, each digit will occur
with nearly the same frequency, odd numbers will be followed by even
numbers about as often as by odd numbers, different pairs of numbers
occur with nearly the same frequency, etc. Since such a process is not
really random, it is called pseudo-random number generator.
Random numbers in computer
The other ways of generating pseudo-random numbers are:

1. Computer simulation languages and indeed some programming languages


such as BASIC have built-in pseudo-random number generators. In computer
simulation situations where this facility is not available in the language you are
using, you will have to write you own pseudo-random number generator (see
how to do this later).

2. The results of experiments such as the one previously describe above are
published in books of statistical tables. In hand simulation, it may be
appropriate to use a published table of random numbers.

3. The conventional six-sided unbiased die may also be used to generate a


sequence of random digits in the set (1, 2, 3, 4, 5, 6) where each digit has a
probability 1/6 of occurrence.
USING THE RND
FUNCTION IN BASIC
Using the rnd function in basic
The BASIC programming language has a numeric function named
RND, which generates random numbers between 0 and 1. Each
time RND is executed, a pseudo random number between 0 and 1
is generated. Using RND function at any time will always generate
the same sequence of pseudo random numbers unless we vary the
random number seed using the BASIC statement:
RANDOMIZE
This way, we can control the sequence of random numbers
generated. RANDOMIZE will result to the following prompt on the
VDU:
Random Number Seed (-32768 to 32767)?
Using the rnd function in basic
Consider the following BASIC program:

FOR K% = 1 TO 5

PRINT RND NEXT K%

END

Adding RANDOMIZE to the program:

RANDOMIZE TIMER FOR K% = 1 TO 5

PRINT RND NEXT K%

END
SIMULATING
RANDOMNESS
Simulating randomness
Suppose we want to simulate the throwing of a fair die. A random
number between 0 and 1 will not always satisfy our needs. If the die is
fair, throwing it several times will yield a series of uniformly distributed
integers 1,2,3,4,5 and 6. Consequently we need to be able to generate
a random integer with values in the range 1 and 6 inclusive.
Now the function RND generates a random number between 0 and 1.
Specifically, the random variable X is in the range: 0 < X < 1
The expression X = RND *6
Will generate a number in the range: 0 < X < 6
We must convert these numbers to integers as follows: X% = INT
(RND*6)
The expression produces an integer in the range: 0 < X < 5
Simulating randomness
But we need the range: 0 < X < 6
Therefore if we need to add 1 to the above expression in
simulating the tossing of a die. Thus,
X% = INT (RND*6) + 1
In general, to generate a random integer between P and N we
use the expression:
INT(RND*N+1-P) + P;
where N>P
While for integer number between 0 and N – 1 we use the
expression INT (RND *N).
PROPERTIES OF A
GOOD RANDOM
NUMBER
GENERATOR
Properties of a Good Random Number
Generator
The random numbers generated should;
a. have as nearly as possible a uniform distribution.
b. should be fast
c. not require large amounts of memory.
d. have a long period.
e. be able to generate a different set of random numbers or a
series of numbers.
f. not degenerate.

You might also like