The RANDOMU function returns one or more uniformly-distributed, floating-point, pseudo-random numbers in the range 0 < Y <1.0.

The random number generator is taken from: "Random Number Generators: Good Ones are Hard to Find", Park and Miller, Communications of the ACM , Oct 1988, Vol 31, No. 10, p. 1192. To remove low-order serial correlations, a Bays-Durham shuffle is added, resulting in a random number generator similar to ran1() in Section 7.1 of Numerical Recipes in C: The Art of Scientific Computing (Second Edition), published by Cambridge University Press.

Calling Sequence

Result = RANDOMU( Seed [, D 1 , ..., D n ] )



A long integer used to initialize the IDL random number generator. Both of the random number generators, RANDOMN and RANDOMU, simulate random floating point numbers using a seqence of long integers. You can use Seed to start the sequence. IDL saves the sequence for subsequent calls to RANDOMN and RANDOMU. If Seed is a named variable, RANDOMN and RANDOMU will update it to the next long integer in the sequence. To generate a random seed from the system time, set Seed equal to an undefined named variable.

D i

The dimensions of the result. The dimension parameters can be any scalar expression. Up to eight dimensions can be specified. If no dimensions are specified, RANDOMU returns a scalar result.


The formulas for the binomial, gamma, and Poisson distributions are from Section 7.3 of Numerical Recipes in C: The Art of Scientific Computing (Second Edition), published by Cambridge University Press.


Set this keyword to a 2-element array, [ n , p ], to generate random deviates from a binomial distribution. If an event occurs with probability p , with n trials, then the number of times it occurs has a binomial distribution.


Set this keyword to an integer order i > 0 to generate random deviates from a gamma distribution. The gamma distribution is the waiting time to the i th event in a Poisson random process of unit mean. A gamma distribution of order equal to 1 is the same as the exponential distribution.


Set this keyword to generate random deviates from a normal distribution.


Set this keyword to the mean number of events occurring during a unit of time. The POISSON keyword returns a random deviate drawn from a Poisson distribution with that mean.


Set this keyword to generate random deviates from a uniform distribution.


This example simulates rolling two dice 10,000 times and plots the distribution of the total using RANDOMU. Enter:


   FIX(6 * RANDOMU(S, 10000)) + 2)

In the above statement, the expression RANDOMU(S, 10000) is a 10,000-element, floating-point array of random numbers greater than or equal to 0 and less than 1. Multiplying this array by 6 converts the range to 0 £ Y < 6.

Applying the FIX function yields a 10,000-point integer vector with values from 0 to 5, one less than the numbers on one die. This computation is done twice, once for each die, then 2 is added to obtain a vector from 2 to 12, the total of two dice.

The HISTOGRAM function makes a vector in which each element contains the number of occurrences of dice rolls whose total is equal to the subscript of the element. Finally, this vector is plotted by the PLOT procedure.

See Also