Mathcom Home
Services Customers Tech Info Contact Us
 

Random Number Generators (RNGs)

  • Web Sites for Random Number Generators
  • Types of Random Number Generators
  • Linear Congruential Generators (LCG)
  • Add-with-carry and Subtract-with-borrow Generators (AWCG, SWBG)
  • Multiply-with-carry Generators (MWCG)
  • Inversive Conguential Generators (ICG)
  • Tests for Randomness
  • Commercial RNGs and Hardware RNGs

    Web Sites for Random Number Generators

    RANDLIB (C and Fortran versions) provides 32 virtual random number generators. Each generator can provide 1,048,576 blocks of numbers, and each block is of length 1,073,741,824. Any generator can be set to the beginning or end of the current block or to its starting value. Packaging is provided so that if these capabilities are not needed, there is a single generator with period 2.3 X 10^18. Using this base, routines are provided that return:

  • Beta random deviates
  • Chi-square random deviates
  • Exponential random deviates
  • F random deviates
  • Gamma random deviates
  • Multivariate normal random deviates (mean and covariance matrix specified)
  • Noncentral chi-square random deviates
  • Noncentral F random deviates
  • Univariate normal random deviates
  • Random permutations of an integer array
  • Real uniform random deviates between specified limits
  • Binomial random deviates
  • Negative Binomial random deviates
  • Multinomial random deviates
  • Poisson random deviates
  • Integer uniform deviates between specified limits
  • Seeds for the random number generator calculated from a character string

    pLab is an excellent web site created by the Department of Mathematics at the Salzburg University. It covers RNGs and tests for randomness, and contains publications, software, and pointers to other resources.

    Additional services may be available from pLab -- see: pLab Overview

    See also the Diehard page, described at: Tests for Randomness

    Another web page with info on RNGs is Skip Carter's page at Taygeta

    Also see Pierre L'Ecuyer's papers:

    Info on 1/f noise, called "flicker noise" or "pink noise", is at Wentian Li's site.

    Some code in Fortran 90 for generating random numbers from a range of discrete and continuous distributions is at Alan Miller's page.

    SPRNG is a scalable parallel random number generator library. (It can be used for the usual serial random number generation too.)

    Types of Random Number Generators

    Random number generators typically consist of three components:
  • The basic generator, described further below.
  • Some generators contain a shuffle box. First described in Marsaglia 1965. Also described in Knuth 1981 and Press et al 1992.
  • A transformation to the desired probability distribution. See Press et al 1992 or, better yet, Simulation Modeling and Analysis by Averill M. Law and W. David Kelton 1991, or Non-Uniform Random Variate Generation by Luc Devroye 1986.

    There are four common types of basic generators.

  • linear congruential (LCG)
  • add-with-carry and subtract-with-borrow (AWCG, SWBG)
  • multiply-with-carry (MWCG)
  • inversive conguential (ICG)

    Linear Congruential Generators (LCG)

    Linear congruential generators are of the form

         x(n) = a * x(n-1) + b mod M

    A good discussion of this type is in the text by Press et al. These are by far the most common form in use, and have periods in the range 10^6 to 10^9 when using 32 bit words. Unfortunately, they have some unpleasant properties. When taken in pairs, triplets, or n-tuples, the random values often fall on only a few planes in n-space. Using a shuffle box can break up this uniformity. For more information on the problems associated with linear congruential generators, see Marsaglia 1968, Marsaglia 1993 and Sullivan 1993. See also Marsaglia's web site, described under Tests for Randomness .

    Add-with-carry and Subtract-with-borrow Generators (AWCG, SWBG)

    Add-with-carry generators have the form:

         x(n) = x(n-s) + x(n-r) + carry mod M

    Subtract-with-borrow generators have the form:

         x(n) = x(n-s) - x(n-r) - carry mod M

    See Marsaglia 1991. These generators have much longer periods, from 10^200 to 10^500, than LCGs, and they are almost as fast as LCGs. Unfortunately they too have the problem of falling mainly on the planes. See Tezuka 1993. Again, a shuffle box, as described in Press et al, can eliminate this problem. The implementation by Marsaglia and Zaman may be found at: Marsaglia's generators.

    Multiply-with-carry Generators (MWCG)

    Multiply-with-carry generators have the form:

         x(n) = a*x(n-1) + carry mod M

    [George Marsaglia]: Here is a simple version, one so simple and good I predict it will be the system generator for many future computers:

         x(n)=a*x(n-1)+carry mod 2^32

    With multiplier 'a' chosen from a large set of easily found integers, the period is a*2^31-1, around 2^60, and I have yet to find a test it will not pass!
    [Charles Knechtel]: George Marsaglia has some interesting new ideas for pseudorandom number generation using MWCG and MWCG combined with other pseudorandom number generators (RNGs); these new ideas are implemented as part of the Diehard suite of RNG tests. The best of these seem to pass all the Diehard tests, even tests that many common pseudorandom number generators fail. Source is at the Diehard page, described at: Tests for Randomness .

    Inversive Conguential Generators (ICG)

    Inversive congruential generators are of the form

         x(n) = a * ~(x(n-1)) + b mod M

    where:
    M is prime
    "~y" denotes the multiplicative inverse of y in the field over {0, 1, ..., M-1} using arithmetic modulo M, and ~0 is 0.

    ICGs do not have the "mainly in the planes" problem. See the pLab, described above at Web Sites for Random Number Generators , for more info on ICGs.

    [Charles Knechtel]: Marsaglia's Diehard suite of RNG tests, at Tests for Randomness also contains a subroutine named makeinvc which implements an ICG and generates a file of pseudorandom numbers named INVCONG.32; however, examination of the FORTRAN source code for makeinvc shows that a modulus M equal to 2^32 was used (see file makewhat.f. Eichenauer-Herrmann (1992, p. 173, 175) notes that certain ICGs with power of two modulus have distributional disadvantages compared to the "excellent quality" of ICGs with prime modulus. Indeed, the documentation for INVCONG.32 remarks that makeinvc fails to pass many of the Diehard tests (see the last section of file makef.txt from the Diehard archive fortran.tar.gz. An ICG with prime modulus should have better uniform properties than makeinvc, and Otmar Lendl's ICG implementation might be speedier than makeinvc.

    Tests for Randomness

    The Diehard suite of RNG generators and tests, by George Marsaglia, is available from: Diehard overview, source, & binaries A similar suite is available from: dieharder

    Also see pLab, described above at Web Sites for Random Number Generators , for descriptions of some tests.

    Commercial RNGs and Hardware RNGs

    Robert Davies' page has a comparison of hardware and software RNGs.

    Protego Hardware Generator is a hardware RNG.



    Copyright 1995-2008 Mathcom Solutions Inc       info@mathcom.com       Updated March 27, 2008