RANDOMN

The RANDOMN function returns one or more normally-distributed, floating-point, pseudo-random numbers with a mean of zero and a standard deviation of one.

RANDOMN uses the Box-Muller method for generating normally-distributed (Gaussian) random numbers.

Calling Sequence

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

Arguments

Seed

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 start the sequence with a "random" seed, call RANDOMN or RANDOMU with Seed set to an undefined named variable. The first seed will be taken from the system time.

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, RANDOMN returns a scalar result

Keywords

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.

BINOMIAL

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.

GAMMA

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.

NORMAL

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

POISSON

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.

UNIFORM

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

Examples

If you start the sequence with an undefined variable--if RANDOMN has already been called, Seed is no longer undefined--IDL initializes the sequence with the system time:

randomValue = RANDOMN(systime_seed); ;Generate one random variable and initialize the sequence with an undefined variable.

PRINT, systime_seed, randomValue

IDL prints the updated systime_seed (no longer undefined) and the floating-point random number:

780458725 0.683157

To generate repeatable experiments, begin the sequence with a particular seed. If RANDOMN has already been called, Seed is no longer undefined; you must restart IDL.

seed_value = 5L

randomValue = RANDOMN(seed_value); ;Generate one random variable and initialize the sequence with 5.

PRINT, seed_value, randomValue

IDL prints the updated seed and the floating-point random number:

1960118772 0.521414

To restart the sequence with a particular seed, call IDL with the the negative of the seed.

SEED = -5L

randomValue = RANDOMN(seed) ; ;Get a normal random number, and restart the sequence with a seed of 5.

PRINT, restart_seed, randomValue

IDL prints the updated seed and the FLOAT random number:

1960118772 0.521414

 

To create a 10 by 10 array of normally-distributed, random numbers, type:

R = RANDOMN(seed, 10, 10)

Since seed is undefined, the system time is used to initialize the random number generator. Print the resulting values by entering:

PRINT, R

 

A more interesting example plots the probability function of 2000 numbers returned by RANDOMN. Type:

PLOT, HISTOGRAM(RANDOMN(SEED, 2000), BINSIZE=0.1)

 

To obtain a sequence of 1000 exponential (gamma distribution, order 1) deviates, type:

Result = RANDOMN(seed, 1000, GAMMA=1)

Intuitively, the result contains a random series of waiting times for events occurring an average of one per time period.

To obtain a series of 1000 random elapsed times required for the arrival of two events, type:

Result = RANDOMN(seed, 1000, GAMMA=2) ; Returns a series of 1000 random elapsed times required for the  arrival of two events.

To obtain a 128 x 128 array filled with Poisson deviates, with a mean of 1.5, type:

Result = RANDOMN(seed, 128, 128, POISSON=1.5)

To simulate the count of "heads" obtained when flipping a coin 10 times, type:

Result = RANDOMN(seed, BINOMIAL=[10,.5])

See Also

RANDOMU