random

random — generates random numbers from 0 to 1.

Syntax

random ()

		

Arguments

none

Returns

A floating point random number which is greater than or equal to 0 and is less than 1.

Description

This function uses a pseudo-random number generator to generate a non-repeating sequence of numbers randomly distributed across the range of 0 <= x < 1.

The random number generator should be seeded prior to being called by using the set_random function. If the same seed is given to set_random, the same random sequence will result every time.

Example

#!/usr/local/bin/gamma -d

//Seed random number generator to clock setting:
set_random(clock());

//Randomly generate an integer from one to six:
function one_to_six ()
{
        floor(6 * random()) + 1;
}

//Princ the results:
x = one_to_six();
princ(x, "\n");
		

See Also

set_random