Browse the docs

rand

Returns a random whole number, optionally below a limit or between two numbers.

Keyboard Maestro: RAND

Details #

rand(a?, b?) takes zero, one or two arguments and returns a random whole number.

  • rand() gives a number from 0 up to about 2.1 billion.

  • rand(limit) gives a number from 0 up to but not including limit. rand(6) is 0 to 5.

  • rand(low, high) gives a number from low to high, both included. rand(1, 6) is 1 to 6.

Decimals in the arguments are cut off. For a random number with decimals, use random.

Parameters #

Takes 0 to 2 arguments. {{ rand(text?, b?) }}

Examples #

rand(1, 1)
→ 1
rand(1, 6)
→ 3
rand(10)
→ 2

Gotchas #

  • rand(0) or a negative limit stops the step: rand() needs a limit above 0.

  • rand(high, low) with the first number larger stops the step: rand() needs the first number to be the smaller.

  • The number is different every time the step runs, so don't use it where a repeatable result matters.