public final class JVMRandom
extends java.util.Random
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).
| Modifier and Type | Field and Description |
|---|---|
private boolean |
constructed
Ensures that only the parent constructor can call reseed.
|
private static long |
serialVersionUID
Required for serialization support.
|
private static java.util.Random |
SHARED_RANDOM |
| Constructor and Description |
|---|
JVMRandom()
Constructs a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
private static int |
bitsRequired(long num)
Count the number of bits required to represent a long number.
|
private static long |
next63bits()
Get the next unsigned random long
|
boolean |
nextBoolean()
Returns the next pseudorandom, uniformly distributed boolean value
from the Math.random() sequence.
|
void |
nextBytes(byte[] byteArray)
Unsupported in 2.0.
|
double |
nextDouble()
Synonymous to the Math.random() call.
|
float |
nextFloat()
Returns the next pseudorandom, uniformly distributed float value
between
0.0 and 1.0 from the Math.random()
sequence. |
double |
nextGaussian()
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 between
0 (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.
|
static long |
nextLong(long n)
Returns a pseudorandom, uniformly distributed long value between
0 (inclusive) and the specified value (exclusive), from
the Math.random() sequence. |
void |
setSeed(long seed)
Unsupported in 2.0.
|
private static final long serialVersionUID
Serializable,
Constant Field Valuesprivate static final java.util.Random SHARED_RANDOM
private boolean constructed
public void setSeed(long seed)
setSeed in class java.util.Randomseed - ignoredjava.lang.UnsupportedOperationExceptionpublic double nextGaussian()
nextGaussian in class java.util.Randomjava.lang.UnsupportedOperationExceptionpublic void nextBytes(byte[] byteArray)
nextBytes in class java.util.RandombyteArray - ignoredjava.lang.UnsupportedOperationExceptionpublic 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.
nextInt in class java.util.Randompublic int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between
0 (inclusive) and the specified value (exclusive), from
the Math.random() sequence.
nextInt in class java.util.Randomn - the specified exclusive max-valuejava.lang.IllegalArgumentException - when n <= 0public 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.
nextLong in class java.util.Randompublic static long nextLong(long n)
Returns a pseudorandom, uniformly distributed long value between
0 (inclusive) and the specified value (exclusive), from
the Math.random() sequence.
n - the specified exclusive max-valuejava.lang.IllegalArgumentException - when n <= 0public boolean nextBoolean()
Returns the next pseudorandom, uniformly distributed boolean value from the Math.random() sequence.
nextBoolean in class java.util.Randompublic float nextFloat()
Returns the next pseudorandom, uniformly distributed float value
between 0.0 and 1.0 from the Math.random()
sequence.
nextFloat in class java.util.Randompublic double nextDouble()
Synonymous to the Math.random() call.
nextDouble in class java.util.Randomprivate static long next63bits()
private static int bitsRequired(long num)
num - long number