About random numbers

This is the documentation for 2.1.4 version, which is not the latest version. Consider upgrading to 3.4.0.

Why it matters

RosaeNLG uses random numbers to choose synonymic alternatives, to choose synonyms and referring expressions. The following features uses random numbers:

  • Synonyms

    • the syn mixin

    • the synz / syn structure

    • the syn_fct function

    • the choosebest structure

    • the itemz / item structure when mix is set to true

Also, RosaeNLG has to be able to "predict what will happen soon":

  • It runs synonymic alternatives just to test if they are empty or not - but without actually keeping them.

  • It also runs referring expression to check their gender and number, before they are triggered for real.

Once the result of these predictions are known, RosaeNLG rollbacks and continues the actual text generation. But when it actually generates the content that was previously predicted, it must produce the same content as predicted: thus it must have the same random numbers.

This means that RosaeNLG does not really generate random numbers on the fly:

  • When RosaeNLG is initialiazed (when renderFile is called typically), it creates an array of random numbers for its own use

  • During text generation, it uses this array to get random numbers

  • When it rollbacks after a prediction, it also rollbacks the current position in this array

You must not use random numbers in text generation otherwise it will confuse RosaeNLG’s prediction system.

Seeds

When rendering a RosaeNLG template, you can set the forceRandomSeed parameter. If set, RosaeNLG will use this random seed. If not set, it will just randomly choose one.

This is useful when doing tests: regression tests, or when you want RosaeNLG to run the text generation and choose the same synonyms each time:

  1. Let RosaeNLG choose the random seed, but output it to keep its track: #{util.randomSeed}

  2. When you want to make tests with the same synonyms: rosaenlgPug.renderFile('template.pug', { language: xxx, forceRandomSeed: yyy } );