Rnd/Ran

Description

The rnd() and ran() functions return a value between 0 and 1 from a uniformly distributed sample.

The initial starting value in the random number range is determined by a seed. The seed is a positive integer and can be set by rnd(seed) or ran(seed).

Note: The seeding algorithm for Origin's methods of random number generation was changed for version 2016. For more information, see documentation for the system variable @ran.

Syntax

double rnd(int seed)
double ran(int seed)

Parameter

seed

a integer used to initialize the returned pseudorandom dataset.
  • If seed is a positive integer, this function will set the seed and return 0.
  • If seed is 0 or a negative integer, or, no argument is provided, this function will return the next number in the random number sequence.

Return

Returns a value between 0 and 1 from a uniformly distributed sample.

Example

The sample script shows you how to set a seed and how to generate random numbers:

int seed = 1;
 
ty "This outputs the same random number:";
for(int i = 1; i <= 3; i++)
{
        if( rnd(seed) == 0 )
                rnd() = ;
}
 
ty "This outputs a different random number each time:";
if( rnd(seed) == 0 )
{
        for(int i = 1; i <= 3; i++)
        {
                // First value is the same as above loop.
                rnd() = ;
        }
}