Java Reference
In-Depth Information
In the case of a coin, if we toss it 144 times, we would expect heads to appear 72 times and tails to appear 72 times.
In practice, these exact values are not normally obtained, but if the coin is a fair one, then the values would be close
enough to the expected values to pass certain statistical tests. For example, a result of 75 heads and 69 tails is close
enough to the expected value of 72 to pass the required tests.
Random numbers are widely used in simulating games of chance (such as games involving dice, coins, or cards),
in playing educational games (such as creating problems in arithmetic), and in modeling real-life situations on a
computer.
For example, if we want to play a game of Snakes and Ladders , throwing the die is simulated by the computer
generating a random number from 1 to 6. Suppose we want to create problems in addition for a child, using only the
numbers from 1 to 9. For each problem, the computer can generate two numbers (for example, 7 and 4) in the range
1 to 9 and give these to the child to add.
But suppose we want to simulate the traffic pattern at a road intersection governed by traffic lights. We want to
time the lights in such a way that the waiting time in both directions is as short as possible. To do the simulation on
a computer, we will need some data as to how fast vehicles arrive at and leave the intersection. This must be done by
observation in order for the simulation to be as useful as possible.
Suppose it is determined that a random number of vehicles (between 5 and 15) going in direction 1 arrive at the
intersection every 30 seconds. Also, between 8 and 20 vehicles arrive every 30 seconds going in direction 2.
The computer can simulate this situation as follows:
1. Generate a random number, r1 , in the range 5 to 15.
2. Generate a random number, r2 , in the range 8 to 20.
r1 and r2 are taken as the numbers of vehicles that arrive at the intersection from each direction in the first
30 seconds. The process is repeated for successive 30-second periods.
6.2 Random and Pseudorandom Numbers
The value that appears when a die is thrown has no effect on what comes up on the next throw. We say that the throws
have independent outcomes and the values thrown are random integers in the range 1 to 6. But when a computer is
used to generate a sequence of random numbers in a given interval, it uses an algorithm.
Normally, the next number in the sequence is generated from the previous number in a prescribed and
predetermined manner. This means the numbers in the sequence are not independent of each other, like they are
when we throw a die, for instance. However, the numbers generated will pass the usual set of statistical tests for
randomness , so, to all intents and purposes, they are random numbers. But, because they are generated in a very
predictable manner, they are usually called pseudorandom numbers.
In modeling many types of situations, it does not usually matter whether we use random or pseudorandom
numbers. In fact, in most applications, pseudorandom numbers work quite satisfactorily. However, consider an
organization running a weekly lottery where the winning number is a six-digit number. Should a pseudorandom
number generator be used to provide the winning number from one week to the next?
Since the generator produces these numbers in a completely predetermined way, it would be possible to predict
the winning numbers for weeks to come. Clearly, this is not desirable (unless you are in charge of the random number
generator!). In this situation, a truly random method of producing the winning numbers is needed.
6.3 Generating Random Numbers by Computer
In what follows, we make no distinction between random and pseudorandom numbers since, for most practical
purposes, no distinction is necessary. Almost all programming languages provide some sort of random number
generator, but there are slight differences in the way they operate.
 
Search WWH ::




Custom Search