This site is no longer updated.Go to new Conversational Cloud docs

$reactions.random


Random number generator.

  • The method accepts one argument, an integer max value.
  • The method returns a random integer from 0 to max (not including maх).

Special features

  • The returned values can be redefined in tests.
  • The returned values can be redefined in the $request.data.smartRandom structure.
  • All the returned values are stored in $response and can be used to re-execute the script with the same results.
  • The method checks the returned values ​​so that random numbers are not repeated more often once per every max / 2 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.
    script:
        $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.