Tagscript

RandomParser

Pick one item at random from a list.

random picks a single item from a list and renders it.

For template authors

Syntax

{random:one,two,three}

The list splits on ~ if the payload contains one, otherwise on ,, otherwise on |. Use ~ when the items themselves contain commas.

Examples

{random:foo,bar,baz}
# foo

{random:Have a great day~Hope you're well, friend~Welcome back}
# Hope you're well, friend

Each random tag rolls on its own. To pick once and reuse the result, store it with =:

{=(who):{random:Parbez,Rkn,Priyansh}}{who} opens the door. {who} looks around.

Aliases

random, rand

For developers

Register the parser

import { Interpreter, RandomParser } from 'tagscript';
const ts = new Interpreter(new RandomParser());

Behaviour

The payload is required and no parameter is used. parse splits with the exported split(payload, true) helper, then indexes with Math.random().

The randomness comes from Math.random(), so do not use this tag to pick anything that needs to be unguessable.

API reference

RandomParser

Last updated on

On this page

Edit on Github