Skip to main content


This method returns a random integer number in the specified range.


The method accepts one argument: an integer max value:


The method returns a random integer from 0 to max (not including max).

Usage details

  • The method return values can be overridden in XML tests using the <random> tag. This ensures that the tests run stably.

    You cannot redefine the return values of the Math.random built-in JavaScript method. Using it in JAICP scripts is not recommended.
  • The return values can be overridden in the script by modifying the $ object.

  • All return values are stored in $response and can be used to re-execute the script with the same results.

  • The method ensures that the returned random numbers are not repeated more often once per every max / 2 consecutive method calls.

How to use

Consider an example state which emulates a dice game and prints a sum of random numbers from 1 to 6:

state: RollDice
intent!: /RollDice
# Generate two random numbers from 1 to 6.
$temp.diceOne = $reactions.random(6) + 1;
$temp.diceTwo = $reactions.random(6) + 1;
# Use string substitutions to form a response.
a: {{$temp.diceOne}} and {{$temp.diceTwo}}, {{$temp.diceOne + $temp.diceTwo}} in total.