Class MersenneTwister

java.lang.Object
nl.tudelft.simulation.jstats.streams.RandomNumberGenerator
nl.tudelft.simulation.jstats.streams.MersenneTwister
All Implemented Interfaces:
Serializable, StreamInterface

public class MersenneTwister extends RandomNumberGenerator
A java implementation of the Mersenne Twister pseudo random number generator.

This is a Java version of the C-program for MT19937: Integer version. genrand() generates one pseudorandom unsigned integer (32bit) which is uniformly distributed among 0 to 2^32-1 for each call. sgenrand(seed) set initial values to the working area of 624 words. (seed is any 32-bit integer except for 0).

Orignally Coded by Takuji Nishimura, considering the suggestions by Topher Cooper and Marc Rieffel in July-Aug. 1997. More information can be found at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/mt.pdf and https://en.wikipedia.org/wiki/Mersenne_Twister.

Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Alexander Verbraeck, Peter Jacobs
See Also:
  • Constructor Details

    • MersenneTwister

      public MersenneTwister()
      constructs a new Mersenne Twister. System.currentTimeMillis() is used as seed value.
    • MersenneTwister

      public MersenneTwister(long seed)
      Constructor using a given seed.
      Parameters:
      seed - long; The initial seed.
  • Method Details

    • next

      public long next(int bits)
      returns the next value in the stream.
      Specified by:
      next in class RandomNumberGenerator
      Parameters:
      bits - int; the number of bits used
      Returns:
      the next value.
    • setSeed

      public void setSeed(long seed)
      Set the seed of the generator.
      Specified by:
      setSeed in interface StreamInterface
      Specified by:
      setSeed in class RandomNumberGenerator
      Parameters:
      seed - long; the new seed