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.

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.

**NOTE: **
RANDOMN and RANDOMU use the same sequence, so starting or restarting the sequence for one starts or restarts the sequence for the other. Some IDL routines use the random number generator, so using them will initialize the seed sequence. An example of such a routine is
CLUST_WTS
.

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.

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:

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.

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:

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

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:

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

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

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: