Next: , Previous: , Up: Internal Routines   [Contents][Index]

15.5.475 random

random( [seed=seed, period=period,] [dimensions] [, /uniform, /normal, /sample, /shuffle, /bits])

Returns an array with the specified dimensions (which must be a set of scalars and/or arrays) filled with pseudo-random numbers. The keywords determine the distribution. If no keyword is specified, then /uniform is assumed.


selects a uniform distribution. If period is also specified, then long numbers between 0 and period - 1 (inclusive) are returned. If period is not also specified, then float numbers between 0 and 1 (exclusive of the endpoints) are returned.


selects a normal distribution with zero mean and unit standard deviation.


selects a uniform distribution between 0 and period - 1 (inclusive), but the numbers are in ascending order and no number appears more than once.


selects a uniform distribution between 0 and period - 1 (inclusive), but no number appears more than once and they are in random order.


selects byte 0s and 1s with equal probability.

seed is an integer seed number for the random number generation: if you specify the same seed, then you get the same sequence of random numbers. There is one seed for /bits and one independent seed for the other distributions. The initial seed is 123459876 for /bits and -123459876 for the other distributions. You may specify a seed and no dimensions in calls to random or any of its cousins. It that case, the seed is set to the specified value, and a scalar 1 is returned.

There are several separate routines that correspond to random with a particular distribution.

The pseudo-random numbers generated when /bits is selected follow from a primitive polynomial modulo 2 with a period of 2^31 - 1, or about 2.1e9.

The method used to generate the pseudo-random numbers with other distributions is Matsumoto and Nishimura’s “Mersenne Twister” mt19937 generator. The period of this generator is 2^19937 - 1, or about 1e6000.

See also: randomb, randomn, randomu, Random Arrays

Next: , Previous: , Up: Internal Routines   [Contents][Index]