Procedural Randomness

version 2 by Aaron Reed

  • Home page
  • Beginning
  • Next

  • Documentation

    In some games, you may discover a need for text that seems to randomly vary, but will consistently display the same thing in the same circumstances. For instance, you may want to add to a room description a bit of random flavor text that stays the same until the player moves to another location.

    To enable this, Procedural Randomness defines a new say phrase "with procedural randomness" that can be used as the ending to a "one of" clause. This will make the pattern of options chosen consistent until you change the extension's seed.

    You may set the seed to either a number, or, more usefully, an object in the game.

        set seed to 45
        set seed to location

    You can then invoke procedural randomness as follows:

        say "[one of]blue[or]red[or]green[with procedural randomness]";

    If you call "with procedural randomness" multiple times without changing the seed, the same pattern of choices will be selected.

    We can also generate procedurally random numbers, again being assured the number or sequence of numbers will be identical given the same starting seed:

        if a procedurally random chance of 3 in 10 succeeds
        let num be a procedurally random number from 1 to 100

    A final note about VMs: if using a numeric seed, the maximum z-machine value is 32,767; on Glulx, it's 2,147,483,647. Note that switching from one VM to the other will cause the same seed to generate different results.