Math & Text
random
$random[]
The $random[] function generates a random number between min (inclusive) and max (exclusive). It is evaluated each time it runs.
Syntax
$random
$random[min;max]
The function accepts either 0 or 2 arguments; one argument is refused.
Parameters
| Parameter | Description |
|---|---|
min |
Optional (together with max). The lower bound of the random range (inclusive). |
max |
Optional (together with min). The upper bound of the random range (exclusive). It must be strictly greater than min. |
Return Value
A random number as a string. Without arguments: an integer from 0 to 9. With min and max: an integer from min up to max - 1 (or, if decimals are enabled with $enableDecimals, a decimal number in [min, max)).
Behavior
- A new value is drawn each time the function is evaluated.
minis inclusive andmaxis exclusive:$random[1;7]returns 1 to 6.- Both bounds must be finite numbers with
maxgreater thanmin; otherwise the error “Random requires increasing finite bounds.” is raised. - Without arguments,
$randomreturns an integer from 0 to 9, or a decimal in[0, 10)when decimals are enabled with$enableDecimals. - While decimals are disabled (default), bounds with a fractional part are rounded up and the range must still contain an integer.
Examples
Random number between 1 and 100
$random[1;101]
Dice roll
🎲 You rolled a **$random[1;7]**!
Random selection in an embed
$title[Prize draw]
$description[The winning number is: **$random[1000;10000]**]
$footer[🎉 Congratulations to the winner!]
Notes
- Use
$randomString[]to generate random alphanumeric strings. - Use
$randomText[]to randomly choose from a list of text options.
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.