Class Random

This provides a random number generator that can be seeded. Math.rand() cannot be seeded. Using a seed will allow me to repeat things in the debugger when my program acts strange.

Constructors

Methods

Constructors

Methods

  • Create a new instance of a random number generator.

    Parameters

    • seed: string = ...

      The result from a previous call to Random.newSeed(). By default this will create a new seed. Either way the seed will be sent to the JavaScript console.

      Typical use: Use the default until you want to repeat something. Then copy the last seed from the log and use here.

    Returns (() => number)

    A function that can be used as a drop in replacement for Math.random().

      • (): number
      • Returns number

    If the seed is invalid this will throw an Error.

  • Returns string

    A new seed value appropriate for use in a call to Random.create(). This will be reasonably random.

    The seed is intended to be opaque, a magic cookie. It's something that's easy to copy and paste. Don't try to parse or create one of these.