RANDOM
Use the RANDOM script function to generate a random number within a specified range, including the minimum and maximum values themselves. You can optionally specify an initial value (basis) that seeds the number generator — when a basis is provided, the same sequence of numbers is always generated in the same order.
Syntax
RANDOM (Minimum, Maximum [, Basis])
Parameters
| Parameter | Description | Format |
|---|---|---|
| Minimum | Minimum value of the generated random number | Number or script variable |
| Maximum | Maximum value of the generated random number | Number or script variable |
| Basis
(Optional) |
Initial value that seeds the number generator. When specified, the same number sequence is always produced in the same order. | Number or script variable |
Return Codes
| Return Value | Condition |
|---|---|
| Number | A random positive integer within the specified range |
Important Considerations
-
If this function is processed simultaneously in another object, the number sequence already generated may be overwritten.
-
Only positive integers (unsigned data type) can be assigned to this function. The result is always a positive integer. For more information, see Script Variable Data Types.
Examples
The following example generates a random number between 1 and 10.
: SET &number# = RANDOM (1, 10)
The following example uses a Basis value of 1 to seed the number generator. The first call produces a fixed result; the second call without a basis continues the sequence. Assuming the first ten values of the generated sequence are 6, 2, 9, 6, 5, 4, 9, 9, 8, and 2, the result stored in &number# will always be 6.
: SET &ret# = RANDOM (&min#, &max#, 1)
: SET &number# = RANDOM (&min#, &max#)
See also: