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.
#!/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 the Automatically Change SP Value section of the PID Emulator chapter in the Cogent Tools Demo and Tutorials book for an example of this function used in context.