RANDOM

Use the RANDOM script function to generate random numbers. The generated random number falls within a range that you specify, including the minimum or maximum values themselves.

You can optionally define the initial value that the number generator uses to generate the number set. In this case, the generated number set is always identical: the same numbers are supplied in the same order. The same number set can be accessed if you use this function again.

If you do not specify an initial value, the script function returns a number that continuously varies between the minimum and maximum values that you specify. For a particular initial value, the generated numerical series is always identical: the same numbers are supplied in the same order.

Syntax

RANDOM (Minimum, Maximum[, Basis])

Parameters

  • RANDOM
    Generates a random number
    Return code: random positive integer within a specified range

  • Minimum
    Minimum value of the generated random number
    Format: number or script variable

  • Maximum
    Maximum value of the generated random number
    Format: number or script variable

  • Basis
    Initial value for generation
    Format: number or script variable

Notes:

  • 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 (unsigned data type) to this script function. For more information, see Script Variable Data Types.
  • The result is always a positive integer.

Examples

The example below shows how to generate a random number between 1 and 10:
:SET &number# = RANDOM(1, 10)

The example below uses a Basis value of 1 as an initial value for generating a number set:
:SET &ret# = RANDOM(&min#, &max#, 1)
:
SET &number# = RANDOM(&min#, &max#)

If you use the function above again, the result will be the same set of values. For the sake of this example, assume that the first ten values of the generated number set are 6, 2, 9, 6, 5, 4, 9, 9, 8 and 2. The result of the first call that is stored in the &number# variable would therefore always be 6.

See also: