RANDOM
Script Function: Generates random numbers.
Syntax
RANDOM (Minimum, Maximum[, Basis])
Syntax |
Description/Format |
---|---|
Minimum |
Minimal value of the generated random number. |
Maximum |
Maximal value of the generated random number. |
Basis |
Initial value for generation. |
Return code |
---|
Random number within the specified range. |
Comment
The script function RANDOM generates random numbers. A number generator creates a number set that is determined by using its initial value - the Basis.
If you do not specify Basis, this script function returns a number that continuously varies between Minimum and Maximum.
If Basis is specified, the random number generator is initialized by this value. The result is a numerical series whose numbers can be read without the Basis being necessary. For a particular initial value, the generated numerical series is always identical: the same numbers are supplied in the same order.
If this script function is processed in a different object at the same time, the numerical series that has already been generated is overwritten.
You can only assign positive integers (data type "unsigned") to this script function. The result is also always a positive integer.
Examples
-
In the first example, this
script function supplies a number between 1 and 10 (both numbers are included).
The result is "3", for example.
:SET &number# = RANDOM(1, 10) - The second example generates a numerical series with the parameter Basis
being used. These values can be accessed if this function is used again. The first 10 values of the generated numerical with the basis "1"
are: 6, 2, 9, 6, 5, 4, 9, 9, 8
and 2. Therefore, the result of the first call that is stored in "&number#" is always "6".
:SET &ret# = RANDOM(&min#, &max#, 1)
:SET &number# = RANDOM(&min#, &max#)
Please note that the generated numerical series when using Basis "1" is an example. Depending on the platform RANDOM is being executed on the series may be different.
See also:
Script element | Description |
---|---|
Performs an addition. | |
SUB | Performs a subtraction. |
MULT | Performs a multiplication. |
MOD | Returns the remainder of a division. |
DIV | Returns the remainder of a division. |
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by Function