[How To] Return random text from a list

First we create a custom Variable
You can find this in Registry -> Custom Variables

Give your variable a Name
Set Response after variable set to Default
and Type to Script

now the fun Part begin
we need a simple script


// This will be our List of return Values
var aQuotes = [
	"Planning world domination",
	"I farted, I will respond when I fall back to earth",
	"Lost my shadow and went to go find it",
	"I'm not talented enough to type and pick my nose at the same time.",
	"I fell out of my chair. This might take a while.",
	"I only have pms on days that end in the letter 'y'.",
	"Don't Worry!, I dont know where I am either."
// Pick a random quoute from our List
var randomNumber = Math.floor(Math.random() * (aQuotes.length));

// and return it
return aQuotes[randomNumber];

So our custom Variable picks a random Quote from list on every call
now create a command for it (Keyword is also possible)

Manage -> Custom commands

Name your command and set as return the name of our previous created Variable

1 Like

It can be simplified to:

const quotes = [
  "Planning world domination",
  "I farted, I will respond when I fall back to earth"

return _.sample(quotes);

_ is lodash, sample() is an function from lodash https://lodash.com/docs/#sample

i know
but i want people to understand how it works
its a starting point to make complex things and then they can use
simpler things for their own things