Class Java2Random
java.lang.Object
java.util.Random
nl.tudelft.simulation.jstats.streams.Java2Random
- All Implemented Interfaces:
Serializable
,RandomGenerator
,StreamInterface
The Java2Random is an extension of the
java.util.Random
class which implements the StreamInterface.
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator
-
Constructor Summary
ConstructorDescriptionCreate a new Java2Random and initializes with System.currentTimeMillis.Java2Random
(long seed) Create a new Java2Random and initialize with a given seed. -
Method Summary
Modifier and TypeMethodDescriptionlong
Return the original seed of the generator with which it has been first initialized.long
getSeed()
Return the seed of the generator.int
nextInt
(int i, int j) Return pseudo-random number from the stream between the integers i (inclusive) and j (inclusive).void
reset()
Reset the stream to use the original seed with which it was initialized.void
restoreState
(byte[] state) Restore the state to an earlier saved state object.byte[]
Save the state of the RNG into an object, e.g. to roll it back to this state.void
setSeed
(long seed) Set the seed of the generator.Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextLong, nextLong
Methods inherited from interface nl.tudelft.simulation.jstats.streams.StreamInterface
nextBoolean, nextDouble, nextFloat, nextInt, nextLong
-
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
- long; the seed to use.
-
-
Method Details
-
reset
public void reset()Reset the stream to use the original seed with which it was initialized.- Specified by:
reset
in interfaceStreamInterface
-
getOriginalSeed
public long getOriginalSeed()Return the original seed of the generator with which it has been first initialized.- Specified by:
getOriginalSeed
in interfaceStreamInterface
- Returns:
- long; the original seed of the generator when it was first initialized
-
nextInt
public int nextInt(int i, int j) Return pseudo-random number from the stream between the integers i (inclusive) and j (inclusive).- Specified by:
nextInt
in interfaceRandomGenerator
- Specified by:
nextInt
in interfaceStreamInterface
- Parameters:
i
- int; the minimal valuej
- int; the maximum value- Returns:
- int; a value between i and j
-
setSeed
public void setSeed(long seed) Set the seed of the generator.- Specified by:
setSeed
in interfaceStreamInterface
- Overrides:
setSeed
in classRandom
- Parameters:
seed
- long; the new seed
-
getSeed
public long getSeed()Return the seed of the generator.- Specified by:
getSeed
in interfaceStreamInterface
- Returns:
- long; the seed
-
saveState
Save the state of the RNG into an object, e.g. to roll it back to this state.- Specified by:
saveState
in interfaceStreamInterface
- Returns:
- the state as an object specific to the RNG.
- Throws:
StreamException
- when getting the state fails.
-
restoreState
Restore the state to an earlier saved state object.- Specified by:
restoreState
in interfaceStreamInterface
- Parameters:
state
- Object; the earlier saved state to which the RNG rolls back.- Throws:
StreamException
- when resetting the state fails.
-