sidered, we assume that the range of simulated
peating the same sequence over the number of
conditions and their frequency of occurrence will
selections that must be made. For applications that
reflect the real world quite well. Our objective in
require only a few numbers to be generated, simple
building the model was to estimate a range of costs
canned generators may suffice. But algorithms that
that an operator might incur using the Northern
utilize MC simulations can require that thousands
Sea Route. Simulation of a large number of voy-
of numbers be generated during each run. As Press
ages for each transit will capture the maximum
et al. (1992, p. 276) indicate, using a generator with
a period that is too short, "... can be disastrous in
and minimum costs as well as the variance that is
likely over the long term.
might well want to evaluate 106 different points,
Random number generator
30 times each...." Although the outcome of such
Monte Carlo simulations depend on selections
drawn from number sequences that are truly ran-
an exercise may appear reassuringly robust to the
dom. Careful choice of algorithms that are used to
unsuspecting, the results may not adequately
represent the processes the routine is intended to
produce random numbers is critical if model re-
simulate.
sults are to be reliable. Press et al. (1992) note that
To ensure that the results of our simulation are
the logic underlying many "canned" random num-
sound, NSRSIM01 uses the long-period RAN2 rou-
ber generators supplied with compilers or operat-
tine presented by Press et al. (1992, p. 280). RAN2
ing systems is flawed, either in terms of the man-
is based on the algorithm of L'Ecuyer (1988), which
ner in which generators provide for initialization
combines two generators with different periods to
or seeding, or, in worse cases, specifics of algo-
rithms used to generate random numbers. One of
produce a long-period generator with a repeat pe-
the most common weaknesses concerns the rela-
riod that is the least common multiple of the two
tively small period over which the number se-
shorter-component periods. RAN2's period ex-
ceeds 2 1018, which should be adequate for any
quence that is generated repeats itself. No genera-
tor will produce an infinitely long sequence of
implementation of NSRSIM01. RAN2 also uses the
random numbers; if an algorithm is run over and
BaysDurham shuffling algorithm (Knuth 1981)
over again, eventually the number sequence will
to guard against serial correlations in random num-
ber series in which the occurrence of particular
repeat itself exactly.* The period of recurrence is
values, although random in their own right, al-
predictable if the random number algorithm is
ways are followed or preceded by numbers of the
known, so it is important to use code that pro-
vides, for all practical purposes, no chance of re-
The seed used to initialize RAN2 is derived from
the date and time read from the system clock when
NSRSIM01 begins executing. NSRSIM01 constructs
* Random number sequences commonly include sec-
a signed 4-byte integer variable from the current
tions where digits repeat (e.g., 92173888940999995132 or
month, day, hour, minute, second, and hundredth
65749749749128361), but this is not the concern addressed
of a second (Fig. 3). Hundredths of a second are
here. Rather, at issue is the natural period unique to each
converted to tenths of a second and a bias is added
random-number-generating algorithm that defines the
so that the sign bit (bit 32) is set to 1 in half the
length of the sequence of numbers that the algorithm is
seeds that are generated. This ensures that the full
capable of producing. If allowed to iterate beyond this
range of positive and negative values afforded by
period, the generator will replicate the same sequence of
the signed 4-byte seed are available. Note that the
numbers with an exactitude perversely characteristic of
same seed can occur more than once, but only if
the machines on which we increasingly rely.
Byte 1
Byte 4
Byte 3
Byte 2
(least significant byte)
(most significant byte)
32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10
9
8
7
6
5
4
3
2
1
1/10 Second
Minute
Second
Hour
Day
Month
Figure 3. Bit-by-bit map of the signed 4-byte integer seed used to initialize RAN2. Date and time data retrieved from
the system clock are combined to create a variable that, within acceptable limits, will produce a unique sequence of
random numbers each time NSRSIM01 is run.
9