* Removed unused methods in ThreadLocalRandom

* Hide ThreadLocalRandom because it's used by LinkedTransferQueue only
This commit is contained in:
Trustin Lee 2010-01-14 11:47:43 +00:00
parent 55b0bc2c2c
commit 397107adc0

View File

@ -47,7 +47,7 @@ import java.util.Random;
* @since 1.7
* @author Doug Lea
*/
public class ThreadLocalRandom extends Random {
final class ThreadLocalRandom extends Random {
// same constants as Random, but must be redeclared because private
private final static long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL;
@ -64,7 +64,7 @@ public class ThreadLocalRandom extends Random {
* allow others since it would cause setting seed in one part of a
* program to unintentionally impact other usages by the thread.
*/
boolean initialized;
private boolean initialized;
// Padding to help avoid memory contention among seed updates in
// different TLRs in the common case that they are located near
@ -98,7 +98,7 @@ public class ThreadLocalRandom extends Random {
*
* @return the current thread's {@code ThreadLocalRandom}
*/
public static ThreadLocalRandom current() {
static ThreadLocalRandom current() {
return localRandom.get();
}
@ -123,103 +123,5 @@ public class ThreadLocalRandom extends Random {
return (int) (rnd >>> 48-bits);
}
/**
* Returns a pseudorandom, uniformly distributed value between the
* given least value (inclusive) and bound (exclusive).
*
* @param least the least value returned
* @param bound the upper bound (exclusive)
* @throws IllegalArgumentException if least greater than or equal
* to bound
* @return the next value
*/
public int nextInt(int least, int bound) {
if (least >= bound) {
throw new IllegalArgumentException();
}
return nextInt(bound - least) + least;
}
/**
* Returns a pseudorandom, uniformly distributed value
* between 0 (inclusive) and the specified value (exclusive).
*
* @param n the bound on the random number to be returned. Must be
* positive.
* @return the next value
* @throws IllegalArgumentException if n is not positive
*/
public long nextLong(long n) {
if (n <= 0) {
throw new IllegalArgumentException("n must be positive");
}
// Divide n by two until small enough for nextInt. On each
// iteration (at most 31 of them but usually much less),
// randomly choose both whether to include high bit in result
// (offset) and whether to continue with the lower vs upper
// half (which makes a difference only if odd).
long offset = 0;
while (n >= Integer.MAX_VALUE) {
int bits = next(2);
long half = n >>> 1;
long nextn = (bits & 2) == 0 ? half : n - half;
if ((bits & 1) == 0) {
offset += n - nextn;
}
n = nextn;
}
return offset + nextInt((int) n);
}
/**
* Returns a pseudorandom, uniformly distributed value between the
* given least value (inclusive) and bound (exclusive).
*
* @param least the least value returned
* @param bound the upper bound (exclusive)
* @return the next value
* @throws IllegalArgumentException if least greater than or equal
* to bound
*/
public long nextLong(long least, long bound) {
if (least >= bound) {
throw new IllegalArgumentException();
}
return nextLong(bound - least) + least;
}
/**
* Returns a pseudorandom, uniformly distributed {@code double} value
* between 0 (inclusive) and the specified value (exclusive).
*
* @param n the bound on the random number to be returned. Must be
* positive.
* @return the next value
* @throws IllegalArgumentException if n is not positive
*/
public double nextDouble(double n) {
if (n <= 0) {
throw new IllegalArgumentException("n must be positive");
}
return nextDouble() * n;
}
/**
* Returns a pseudorandom, uniformly distributed value between the
* given least value (inclusive) and bound (exclusive).
*
* @param least the least value returned
* @param bound the upper bound (exclusive)
* @return the next value
* @throws IllegalArgumentException if least greater than or equal
* to bound
*/
public double nextDouble(double least, double bound) {
if (least >= bound) {
throw new IllegalArgumentException();
}
return nextDouble() * (bound - least) + least;
}
private static final long serialVersionUID = -5851777807851030925L;
}