6.03 Random Number Generation

As with all computer systems the the numbers generated by the Random function are in fact pseudo-random numbers. They are generated by a formula and two sequences started with the same seed will return the same numbers.

The random number generator is restarted using the argument passed with the Seed option.

Random

Description:

The Random function returns a random number.

Syntax:

random[(opt)]
[random] seed [value]

Parameters:

opt
Depending on the option provided the function returns a random number of a particular type and range.

1 Returns a real number in the range 0.0 to .99999999. This is the default if no argument is provided.
0 Returns an unsigned integer in the range 0 - 4,294,967,295 (OxFFFFFFFF).
n Returns an unsigned integer in the range 1 to n.
-1 Returns the previous random number.
-n Seeds the random sequence generator with this value and n is returned.
value
A value used to seed the random number generator. If omitted the current time stamp value is used.

Return Value:

The returned number depends on the option specified.

Remarks:

As with all computer systems the the numbers generated by the Random function are in fact pseudo-random numbers. They are generated by a formula, and any two sequences started with the same seed will return the same numbers.

For every different value used with the seed option, the random number generator can be expected to generate a different series of numbers in subsequent calls.

If the seed is set to 1, the generator is reset to its initial value and produces the same values as would be provided without a seed.

In order to generate random numbers, the seed is normally set to a unique value, very often using the system time.

The system time stamp changes every second and this interval is probably sufficient for most purposes. If a smaller interval is needed the elapsed time clock returns values with a nominal microsecond resolution, although the actual values returned may be restricted to a lower resolution.

Example:

random seed time(T)   // restart using the current system time stamp
seed time(T)   // restart using the current system time stamp
put random(3)  // an unsigned integer in the range 1 to 3

Implementation Status:

LynPlex Interpreter
Fully implemented, but seed is a separate command
LynPlexC Compiler
Only real random numbers are generated using the rnd function. This is equivalent to random(1).
The seed is set using the randomize command.
LynPlexS Compiler
Random number generation is currently supported by a range of functions.

lynplex/lp0603.txt · Last modified: 2014/11/22 17:07 (external edit)