Skip to main content

chooseAtRandom

Randomly selects and outputs one expression from those provided as parameters.

This function makes it easy to add random linguistic variation (lexical or syntactic) to your narratives.

The function's behavior is affected by your project's STRATEGY setting. See Settings > Variation for details.

Parameters

  • STRING 1(string)

    A string that may be selected at random.

  • STRING 2(string)

    A string that may be selected at random.

  • STRING n(string)

    A string that may be selected at random.

Note

You can input can any ATL element — e.g. function, variable, script call, etc. — that returns a string. You can also input lists, meaning you can enter one list of strings rather than each string separately — see List examples for guidance.

Examples

You can use chooseAtRandom to add lexical variation to your script. This is when different words or phrases are chosen randomly to express the same concept. For example:

Sales have [[chooseAtRandom('decreased', 'slumped', 'fallen')]]

The function outputs one of three possible results, selected at random.

Possible Result 1

Possible Result 2

Possible Result 3

Sales have decreased

Sales have slumped

Sales have fallen

The function also helps with syntactic variation. This involves providing alternative structures for a sentence (or whole paragraph), which are then selected at random. The best approach is to put the variants — e.g. three different passages communicating the same idea — in separate scripts, then use chooseAtRandom to select.

[[chooseAtRandom(Script1, Script2, Script3)]]

Possible Result 1

Possible Result 2

Possible Result 3

All text from Script1

All text from Script2

All text from Script3

Tip

The Describing each row tutorial includes a step-by-step guide to adding linguistic variation.

List examples

The function can also handle lists.

[[

theBeatles = makeList('John', 'Paul', 'George', 'Ringo')

joinStrings('My favorite is ', chooseAtRandom(theBeatles))

]]

Here the function takes one parameter — that is, a list of strings. There are four possible outputs:

Possible Result 1

Possible Result 2

Possible Result 3

Possible Result 4

My favorite is John

My favorite is Paul

My favorite is George

My favorite is Ringo

Note

If you input multiple lists, the function returns one value from one list.