random

Pseudo random number generator

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Random generates a sequence of uniform distributed pseudo-random numbers. The algorithm is a variant of the multiplicative congruential algorithm, known as the Wichmann-Hill generator:

x(k) = (a1*x(k-1)) mod m1
y(k) = (a2*y(k-1)) mod m2
z(k) = (a3*z(k-1)) mod m3
U(k) = (x(k)/m1 + y(k)/m2 + z(k)/m3) mod 1

This generates pseudo-random numbers U(k) uniformly distributed in the interval (0,1). There are many forms of generators depending on the parameters m (prime numbers) and a. The sequence needs an initial Integer vector {x,y,z} known as the seed. The use of the same seed will lead to the same sequence of numbers.

Remarks

Random number generators (RNG) are pseudo-functions which are not true functions but algorithms which deliver a fixed sequence of (usually Integer) numbers which should have a very large period before they repeat itself and appropriate statistic properties such that the sequence appears to be a random draw. For real-valued random numbers, the integers are scaled to the real interval 0.0-1.0. They result in a uniformly distributed random variate between 0-1, which has to be transformed to give a random variate of a wanted distribution. There are two types of techniques for transforming random variates:

  • Acceptance-Rejection techniques
  • Transformation techniques

Acceptance-Rejection techniques throw away some of the generated variates and are thus less efficient. They can not be avoided for all distributions. A good summary about random number generation and most of the transformation techniques used below is given in:

Discrete Event Simulation
Jerry Banks and John S. Carson II
Prentice Hall Inc.
Englewood Cliffs, New Jersey

Some of the other references are quoted below.

WICHMANN-HILL RANDOM NUMBER GENERATOR
Wichmann, B. A. & Hill, I. D. (1982)
  Algorithm AS 183:
  An efficient and portable pseudo-random number generator
  Applied Statistics 31 (1982) 188-190
see also:
  Correction to Algorithm AS 183
  Applied Statistics 33 (1984) 123
McLeod, A. I. (1985)
  A remark on Algorithm AS 183
  Applied Statistics 34 (1985),198-200
In order to completely avoid external functions, all seeds are
set via parameters. For simulation purposes this is almost
always the desired behaviour.
Translated by Hubertus Tummescheit from Python source provided by
Guido van Rossum translated from C source by Adrian Baddeley.
http://www.python.org/doc/current/lib/module-random.html
R A N D O M   V A R I A B L E   G E N E R A T O R S
distributions on the real line:
------------------------------
    normal (Gaussian) 2 versions

Reference Literature

  • function random: Wichmann, B. A. & Hill, I. D. (1982), Algorithm AS 183:
    An efficient and portable pseudo-random number generator, Applied Statistics 31 (1982) 188-190
    see also: Correction to Algorithm AS 183, Applied Statistics 33 (1984) 123
    McLeod, A. I. (1985), A remark on Algorithm AS 183, Applied Statistics 34 (1985),198-200
  • function normalvariate: Kinderman, A.J. and Monahan, J.F., 'Computer generation of random variables using the ratio of uniform deviates', ACM Trans Math Software, 3, (1977), pp257-260.
  • function gaussianvariate: Discrete Event Simulation, Jerry Banks and John S. Carson II,
    Prentice Hall Inc. Englewood Cliffs, New Jersey, page 315/316

Copyright © Hubertus Tummescheit and Department of Automatic Control, Lund University, Sweden.

This Modelica function is free software; it can be redistributed and/or modified under the terms of the BSD-3-Clause license.

Syntax

(x, seedOut) = random(seedIn)

Inputs (1)

seedIn

Type: Integer[3]

Description: Integer vector defining random number sequence, e.g., {23,87,187}

Outputs (2)

x

Type: Real

Description: Random number between 0 and 1

seedOut

Type: Integer[3]

Description: Modified seed to be used for next call of random()