Class Java2Random

java.lang.Object
java.util.Random
nl.tudelft.simulation.jstats.streams.Java2Random
All Implemented Interfaces:
Serializable, RandomGenerator, StreamInterface

public class Java2Random extends Random implements StreamInterface
The Java2Random is an extension of the java.util.Random class which implements the StreamInterface.

Copyright (c) 2002-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information DSOL Manual. The DSOL project is distributed under a three-clause BSD-style license, which can be found at DSOL License.

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

    • Java2Random

      public Java2Random()
      Create a new Java2Random and initializes with System.currentTimeMillis.
    • Java2Random

      public Java2Random(long seed)
      Create a new Java2Random and initialize with a given seed.
      Parameters:
      seed - the seed to use.
  • Method Details

    • reset

      public void reset()
      Description copied from interface: StreamInterface
      Reset the stream to use the original seed with which it was initialized.
      Specified by:
      reset in interface StreamInterface
    • getOriginalSeed

      public long getOriginalSeed()
      Description copied from interface: StreamInterface
      Return the original seed of the generator with which it has been first initialized.
      Specified by:
      getOriginalSeed in interface StreamInterface
      Returns:
      the original seed of the generator when it was first initialized
    • nextInt

      public int nextInt(int i, int j)
      Description copied from interface: StreamInterface
      Return pseudo-random number from the stream between the integers i (inclusive) and j (inclusive).
      Specified by:
      nextInt in interface RandomGenerator
      Specified by:
      nextInt in interface StreamInterface
      Parameters:
      i - the minimal value
      j - the maximum value
      Returns:
      a value between i and j
    • setSeed

      public void setSeed(long seed)
      Description copied from interface: StreamInterface
      Set the seed of the generator.
      Specified by:
      setSeed in interface StreamInterface
      Overrides:
      setSeed in class Random
      Parameters:
      seed - the new seed
    • getSeed

      public long getSeed()
      Description copied from interface: StreamInterface
      Return the seed of the generator.
      Specified by:
      getSeed in interface StreamInterface
      Returns:
      the seed