JVMRandom
is a wrapper that supports all possible
* Random methods via the {@link java.lang.Math#random()} method
* and its system-wide {@link Random} object.
Returns the next pseudorandom, uniformly distributed int value * from the Math.random() sequence.
* * @return the random int */ public int nextInt() { return nextInt(Integer.MAX_VALUE); } /** *Returns a pseudorandom, uniformly distributed int value between
* 0
(inclusive) and the specified value (exclusive), from
* the Math.random() sequence.
n <= 0
*/
public int nextInt(int n) {
if (n <= 0) {
throw new IllegalArgumentException(
"Upper bound for nextInt must be positive"
);
}
// TODO: check this cannot return 'n'
return (int)(Math.random() * n);
}
/**
* Returns the next pseudorandom, uniformly distributed long value * from the Math.random() sequence.
* @return the random long */ public long nextLong() { // possible loss of precision? return nextLong(Long.MAX_VALUE); } /** *Returns a pseudorandom, uniformly distributed long value between
* 0
(inclusive) and the specified value (exclusive), from
* the Math.random() sequence.
n <= 0
*/
public static long nextLong(long n) {
if (n <= 0) {
throw new IllegalArgumentException(
"Upper bound for nextInt must be positive"
);
}
// TODO: check this cannot return 'n'
return (long)(Math.random() * n);
}
/**
* Returns the next pseudorandom, uniformly distributed boolean value * from the Math.random() sequence.
* * @return the random boolean */ public boolean nextBoolean() { return Math.random() > 0.5; } /** *Returns the next pseudorandom, uniformly distributed float value
* between 0.0
and 1.0
from the Math.random()
* sequence.
Synonymous to the Math.random() call.
* * @return the random double */ public double nextDouble() { return Math.random(); } }