763 Generating Random Numbers
c. The fi rst random number is Random = X
2
− Integer(X
2
), where Integer(X
2
) is the
integer part of X
2
.
d. Repeat the process, letting Seed = Random.
Implement this random-number generator in a VBA program similar to
RandomList, and produce a list of 50 random numbers.
3. Defi ne AmodB as the remainder when A is divided by B. For example, 36mod25 =
11. Excel has this function; it is written Mod(A,B). Now here is another random-
number generator:
a. Let X
0
= 1.
b. Let X
n+1
= (7 * X
n
)mod10
8
.
c. Let U
n+1
= X
n+1
/10
8
.
The list of numbers U
1
, U
2
, . . . contains the pseudo-random numbers generated by
this random-number generator. (This is one of the many random-number generators
given in Abramowitz and Stegun, 1972).
Use VBA to produce this random number generator, and use it in a program
similar to UniformRandom.
4. Many states have daily lotteries, which are played as follows: Sometime during the
day, you buy a lottery ticket, on which the seller inscribes a number you choose,
between 000 and 999. That night there is a drawing on television in which a three-
digit number is drawn. If the number on your ticket matches the number drawn,
you win and collect $500 (for a $1 wager). If you lose, you get nothing.
a. Write an Excel function that produces a random number between 000 and 999.
(Hint: Use Rand( ) and Int( ).)
b. Write a VBA program that reproduces 250 random draws of the daily lottery
(about one year’s worth, if there are no drawings on weekends). Assuming that
each ticket costs $1, and assuming that you choose the same number each day,
how much would you have won during the year?
5. Program normalSimulation but put the output into more bins (can you make the
number of bins and their size controllable from the spreadsheet?). Does this get rid
of the “fat tails” in the distribution graph?
6. It is well-known that if Z is a standard normal random variable (i.e., with mean
μ = 0 and standard deviation σ = 1) then X = aZ + b is normally distributed with
μ = b and σ = a. Modify normalSimulation to produce normal, nonstandard, distribu-
tions, with the mean and the standard deviation inputted from the spreadsheet.
7. a. Use NormSInv to produce a list of 1,000 random numbers and use Frequency to
see whether they are indeed normally distributed with mean μ = 0 and standard
deviation σ = 1.
b. Following exercise 6, modify the numbers so that they are distributed with μ = b
and σ = a.