Skip to main content
Engineering LibreTexts

5.7: Pseudo-random Number Generation

  • Page ID
    30981
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    All of the random sampling strategies discussed in the previous section require a random sample uniformly distributed in the range (0,1). Fortunately, there are several well known algorithms for generating such samples, called pseudo - random numbers. These algorithms are deterministic. However, the properties of the sequence of pseudo-random numbers make them look random. These properties include the following:

    1. The numbers do not exhibit any statistical correlation with each other.
    2. The numbers appear to be uniformly distributed in the range (0,1).
    3. There are many, many (at least 1,000,000) numbers in sequence.
    4. All possible numbers in the sequence are generated before any number repeats.

    Because the pseudo-random number generation algorithms are deterministic, a sequence of numbers can be regenerated whenever necessary. This is important in simulation both for debugging and experimentation using common random numbers. Imagine the difficulty of removing a bug from a model if the results were randomly different each time the model was executed!

    A sequence of pseudo-random numbers is called a stream. Having multiple streams of random numbers allows sampling from each particular probability distribution used in a model to be associated with a particular stream. For example in the two stations in a series model, the time between arrivals and the operation time at station A would be assigned different streams. This means for example that if the probability distribution modeling the operation time at station A were changed, the times between arrivals would remain the same.

    As in the previous section, one approach to pseudo-random number generation will be presented. Other approaches for generating pseudo-random numbers are given in Banks, Carson, Nelson, and Nicol (2009) as well as Law (2007). Schmeiser (1980) provides a comprehensive survey.

    Perhaps the most common type of pseudo-random number generation algorithm, with respect to use in simulation languages, is the linear congruential generator (Lehmer, 1951). The linear congruential generator (LCG) has the form:

    \begin{align}Z_{i}=\left(a^{*} Z_{i-1}+c\right) \bmod (m)\tag{5-3}\end{align}

    \begin{align}r_{i}=Z_{i} / m\tag{5-4}\end{align}

    The Zi ’s are a set of integers that range from 0 to m-1. The integer Zi is a remainder and m is the divisor. Other parameters of the generator are a multiplier a, an increment c, and the first integer Z0. The pseudo-random number ri is obtained by dividing Zi by m. Fortunately for our purposes, values for the parameters (a, c, m, and Z0) that result in the desirable properties listed above are used by commercial simulation languages.

    The generator is recursive that is Zi is a function of Zi-1 . Note that at most, m distinct Zi ’s and thus ri’s (pseudo-random numbers) can be obtained. Once Z0 is generated a second time, the entire sequence of Zi’s, and thus ri’s, will be repeated and in the same sequence as the first time.

    Consider the example LCG shown in Table 5-3. The LCG parameter values are shown in the table. Note that the Zi’s range from 0-8. All nine of the Zi’s are generated before any value repeats. Thus, the ri’s appear to be as uniformly distributed in the range (0,1) as nine numbers can be. The statistical correlation between the ri’s is low, 0.030. Since the number of values generated is only 9, the value of m is too small for an effective LCG. However, it suffices for an example.

    Table 5-3: Example LCG
    i Zi ri
    M 9 0 8 0.889
    A 4 1 1 0.111
    C 5 2 0 0.000
    3 5 0.556
    4 7 0.778
    5 6 0.667
    6 2 0.222
    7 4 0.444
    8 3 0.333
    9 8 0.889
    10 1 0.111
    11 0 0.000
    12 5 0.556

    5.7: Pseudo-random Number Generation is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?