simple-prng
    Preparing search index...

    Class PRNG

    A simple Pseudo Random Number Generator class

    Index

    Constructors

    • A simple Pseudo Random Number Generator class

      Returns PRNG

      const rng = new PRNG();
      

    Methods

    • Initialize the PRNG with a seed. Reset the sequence if called with the same seed.

      Parameters

      • seed: number

        Value of the seed (Positive integer) )

      Returns void

      const rng = new PRNG();
      rng.initialize(19650218);

      assert.equal(
      [rng.random(), rng.random(), rng.random(),]
      [0.5414691786281765, 0.11225925898179412, 0.9725827916990966]
      )

      // Initialize again with the same seed resets the sequence
      rng.initialize(19650218);

      assert.equal(
      [rng.random(), rng.random(), rng.random(),]
      [0.5414691786281765, 0.11225925898179412, 0.9725827916990966]
    • Returns a random float in range 0 <=x < 1.

      TODO: The original Mercenne code returns 32 bits precision, in JS we have 53 bits of precision, that might mess up our results. I need to check if the conversion is done properly

      Returns number

      Error if PRNG was not initialized before calling this method

      const rng = new PRNG();
      rng.initialize(19650218);

      assert.equal(rng.random(), 0.5414691786281765)
    • Returns a random 32 bit positive integer. We might want to remove that in the future

      Returns number

      Error if PRNG was not initialized before calling this method

      const rng = new PRNG();
      rng.initialize(19650218);

      assert.equal(rng.randomInt(), 2325592414)