Rnd/Ran/Rand
Contents
Description
The rnd(), ran() and rand() 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) or rand(seed).
Note:
|
Syntax
double rnd(int seed)
double ran(int seed)
double rand(int seed)
Parameter
seed
- Optional, 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() = ; } }