Class MersenneTwisterRandom

  • All Implemented Interfaces:
    ByteArrayReseedableRandom, EntropyCountingRandom, RepeatableRandom, Dumpable, Serializable

    public class MersenneTwisterRandom
    extends BaseRandom

    Random number generator based on the Mersenne Twister algorithm developed by Makoto Matsumoto and Takuji Nishimura.

    This is a very fast random number generator with good statistical properties (it passes the full DIEHARD suite). This is the best RNG for most experiments. If a non-linear generator is required, use the slower AesCounterRandom RNG.

    This PRNG is deterministic, which can be advantageous for testing purposes since the output is repeatable. If multiple instances of this class are created with the same seed they will all have identical output.

    This code is translated from the original C version and assumes that we will always seed from an array of bytes. I don't pretend to know the meanings of the magic numbers or how it works, it just does.

    NOTE: Because instances of this class require 128-bit seeds, it is not possible to seed this RNG using the setSeed(long) method inherited from Random. Calls to this method will have no effect. Instead the seed must be set by a constructor.

    Author:
    Makoto Matsumoto and Takuji Nishimura (original C version), Daniel Dyer (Java port)
    See Also:
    Serialized Form
    • Constructor Detail

      • MersenneTwisterRandom

        public MersenneTwisterRandom()
                              throws SeedException
        Creates a new RNG and seeds it using the default seeding strategy.
        Throws:
        SeedException - if any.
      • MersenneTwisterRandom

        public MersenneTwisterRandom​(byte[] seed)
        Creates an RNG and seeds it with the specified seed data.
        Parameters:
        seed - 16 bytes of seed data used to initialize the RNG.
      • MersenneTwisterRandom

        public MersenneTwisterRandom​(SeedGenerator seedGenerator)
                              throws SeedException
        Seed the RNG using the provided seed generation strategy.
        Parameters:
        seedGenerator - The seed generation strategy that will provide the seed value for this RNG.
        Throws:
        SeedException - If there is a problem generating a seed.