RangeParser
Pick a random number between two bounds.
range picks a whole number between two bounds. rangef picks one with a single decimal place.
For template authors
Syntax
{range:min-max}
{range:min,max}
{rangef:min-max}Both bounds are included, so {range:1-6} can return 1 and can return 6.
Examples
Your lucky number is {range:10-30}!
# Your lucky number is 14!
Dice roll: {range:1,6}
# Dice roll: 6
I am guessing your height is {rangef:5-7}ft.
# I am guessing your height is 5.3ft.Roll once and reuse it with =:
{=(roll):{range:1-6}}You rolled {roll}. {if({roll}>4):Nice!|Bad luck.}Aliases
range for whole numbers, rangef for one decimal place.
For developers
Register the parser
import { Interpreter, RangeParser } from 'tagscript';
const ts = new Interpreter(new RangeParser());Behaviour
The payload is required and no parameter is used. The payload splits on - when it contains one, otherwise on ,.
Because - is the separator, negative bounds do not parse. {range:-5-5} is read as an empty lower bound. Use , if you need one, and be aware the whole range still has to be numbers parseInt accepts.
Both ends are inclusive. rangef works in tenths internally and divides by 10, so it returns one decimal place.
Values come from Math.random() and are not suitable for anything security related.
API reference
Last updated on