Class JVMRandom
- All Implemented Interfaces:
Serializable
,RandomGenerator
JVMRandom
is a wrapper that supports all possible
Random methods via the Math.random()
method
and its system-wide Random
object.
It does this to allow for a Random class in which the seed is shared between all members of the class - a better name would have been SharedSeedRandom.
N.B. the current implementation overrides the methods
Random.nextInt(int)
and Random.nextLong()
to produce positive numbers ranging from 0 (inclusive)
to MAX_VALUE (exclusive).
- Since:
- 2.0
- Version:
- $Id: JVMRandom.java 911986 2010-02-19 21:19:05Z niallp $
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the next pseudorandom, uniformly distributed boolean value from the Math.random() sequence.void
nextBytes
(byte[] byteArray) Unsupported in 2.0.double
Synonymous to the Math.random() call.float
Returns the next pseudorandom, uniformly distributed float value between0.0
and1.0
from the Math.random() sequence.double
Unsupported in 2.0.int
nextInt()
Returns the next pseudorandom, uniformly distributed int value from the Math.random() sequence.int
nextInt
(int n) Returns a pseudorandom, uniformly distributed int value between0
(inclusive) and the specified value (exclusive), from the Math.random() sequence.long
nextLong()
Returns the next pseudorandom, uniformly distributed long value from the Math.random() sequence.long
nextLong
(long n) Returns a pseudorandom, uniformly distributed long value between0
(inclusive) and the specified value (exclusive), from the Math.random() sequence.void
setSeed
(long seed) Unsupported in 2.0.Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next
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, nextInt, nextLong
-
Constructor Details
-
JVMRandom
public JVMRandom()Constructs a new instance.
-
-
Method Details
-
setSeed
public void setSeed(long seed) Unsupported in 2.0.- Overrides:
setSeed
in classRandom
- Parameters:
seed
- ignored- Throws:
UnsupportedOperationException
-
nextGaussian
public double nextGaussian()Unsupported in 2.0.- Specified by:
nextGaussian
in interfaceRandomGenerator
- Overrides:
nextGaussian
in classRandom
- Returns:
- Nothing, this method always throws an UnsupportedOperationException.
- Throws:
UnsupportedOperationException
-
nextBytes
public void nextBytes(byte[] byteArray) Unsupported in 2.0.- Specified by:
nextBytes
in interfaceRandomGenerator
- Overrides:
nextBytes
in classRandom
- Parameters:
byteArray
- ignored- Throws:
UnsupportedOperationException
-
nextInt
public int nextInt()Returns the next pseudorandom, uniformly distributed int value from the Math.random() sequence.
Identical tonextInt(Integer.MAX_VALUE)
N.B. All values are >= 0.
- Specified by:
nextInt
in interfaceRandomGenerator
- Overrides:
nextInt
in classRandom
- Returns:
- the random int
-
nextInt
public int nextInt(int n) Returns a pseudorandom, uniformly distributed int value between
0
(inclusive) and the specified value (exclusive), from the Math.random() sequence.- Specified by:
nextInt
in interfaceRandomGenerator
- Overrides:
nextInt
in classRandom
- Parameters:
n
- the specified exclusive max-value- Returns:
- the random int
- Throws:
IllegalArgumentException
- whenn <= 0
-
nextLong
public long nextLong()Returns the next pseudorandom, uniformly distributed long value from the Math.random() sequence.
Identical tonextLong(Long.MAX_VALUE)
N.B. All values are >= 0.
- Specified by:
nextLong
in interfaceRandomGenerator
- Overrides:
nextLong
in classRandom
- Returns:
- the random long
-
nextLong
public long nextLong(long n) Returns a pseudorandom, uniformly distributed long value between
0
(inclusive) and the specified value (exclusive), from the Math.random() sequence.- Parameters:
n
- the specified exclusive max-value- Returns:
- the random long
- Throws:
IllegalArgumentException
- whenn <= 0
-
nextBoolean
public boolean nextBoolean()Returns the next pseudorandom, uniformly distributed boolean value from the Math.random() sequence.
- Specified by:
nextBoolean
in interfaceRandomGenerator
- Overrides:
nextBoolean
in classRandom
- Returns:
- the random boolean
-
nextFloat
public float nextFloat()Returns the next pseudorandom, uniformly distributed float value between
0.0
and1.0
from the Math.random() sequence.- Specified by:
nextFloat
in interfaceRandomGenerator
- Overrides:
nextFloat
in classRandom
- Returns:
- the random float
-
nextDouble
public double nextDouble()Synonymous to the Math.random() call.
- Specified by:
nextDouble
in interfaceRandomGenerator
- Overrides:
nextDouble
in classRandom
- Returns:
- the random double
-