|
FlexDoc/Javadoc 2.0 Demo Java Doc |
Usages of this class should typically be of the form: ThreadLocalRandom.current().nextX(...) (where X is Int, Long, etc). When all usages are of this form, it is never possible to accidentally share a ThreadLocalRandom across multiple threads.
This class also provides additional commonly used bounded random generation methods.
Instances of ThreadLocalRandom are not cryptographically secure. Consider instead using SecureRandom in security-sensitive applications. Additionally, default-constructed instances do not use a cryptographically random seed unless the system property java.util.secureRandomSeed is set to true.
Nested Class Summary |
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator |
Method Summary |
||
static ThreadLocalRandom |
current()
Returns the current thread's ThreadLocalRandom object.
|
|
doubles()
Returns an effectively unlimited stream of pseudorandom
double values, each between zero (inclusive) and one
(exclusive).
|
||
doubles(double randomNumberOrigin, double randomNumberBound)
Returns an effectively unlimited stream of pseudorandom
double values, each conforming to the given origin (inclusive) and bound
(exclusive).
|
||
doubles(long streamSize)
Returns a stream producing the given streamSize number of
pseudorandom double values, each between zero
(inclusive) and one (exclusive).
|
||
doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
Returns a stream producing the given streamSize number of
pseudorandom double values, each conforming to the given origin
(inclusive) and bound (exclusive).
|
||
ints()
Returns an effectively unlimited stream of pseudorandom int
values.
|
||
ints(int randomNumberOrigin, int randomNumberBound)
Returns an effectively unlimited stream of pseudorandom
int values, each conforming to the given origin (inclusive) and bound
(exclusive).
|
||
ints(long streamSize)
Returns a stream producing the given streamSize number of
pseudorandom int values.
|
||
ints(long streamSize, int randomNumberOrigin, int randomNumberBound)
Returns a stream producing the given streamSize number
of pseudorandom int values, each conforming to the given
origin (inclusive) and bound (exclusive).
|
||
longs()
Returns an effectively unlimited stream of pseudorandom long
values.
|
||
longs(long streamSize)
Returns a stream producing the given streamSize number of
pseudorandom long values.
|
||
longs(long randomNumberOrigin, long randomNumberBound)
Returns an effectively unlimited stream of pseudorandom
long values, each conforming to the given origin (inclusive) and bound
(exclusive).
|
||
longs(long streamSize, long randomNumberOrigin, long randomNumberBound)
Returns a stream producing the given streamSize number of
pseudorandom long, each conforming to the given origin
(inclusive) and bound (exclusive).
|
||
protected int |
next(int bits)
Generates a pseudorandom number with the indicated number of
low-order bits.
|
|
boolean |
Returns the next pseudorandom, uniformly distributed
boolean value from this random number generator's
sequence.
|
|
double |
Returns the next pseudorandom, uniformly distributed
double value between 0.0 and
1.0 from this random number generator's sequence.
|
|
double |
nextDouble(double bound)
Returns a pseudorandomly chosen double value between zero
(inclusive) and the specified bound (exclusive).
|
|
double |
nextDouble(double origin, double bound)
Returns a pseudorandomly chosen double value between the
specified origin (inclusive) and the specified bound (exclusive).
|
|
float |
Returns the next pseudorandom, uniformly distributed float
value between 0.0 and 1.0 from this random
number generator's sequence.
|
|
float |
nextFloat(float bound)
Returns a pseudorandomly chosen float value between zero
(inclusive) and the specified bound (exclusive).
|
|
float |
nextFloat(float origin, float bound)
Returns a pseudorandomly chosen float value between the
specified origin (inclusive) and the specified bound (exclusive).
|
|
int |
nextInt()
Returns the next pseudorandom, uniformly distributed int
value from this random number generator's sequence.
|
|
int |
nextInt(int bound)
Returns a pseudorandom, uniformly distributed int value
between 0 (inclusive) and the specified value (exclusive), drawn from
this random number generator's sequence.
|
|
int |
nextInt(int origin, int bound)
Returns a pseudorandomly chosen int value between the specified
origin (inclusive) and the specified bound (exclusive).
|
|
long |
nextLong()
Returns the next pseudorandom, uniformly distributed long
value from this random number generator's sequence.
|
|
long |
nextLong(long bound)
Returns a pseudorandomly chosen long value between zero
(inclusive) and the specified bound (exclusive).
|
|
long |
nextLong(long origin, long bound)
Returns a pseudorandomly chosen long value between the
specified origin (inclusive) and the specified bound (exclusive).
|
|
void |
setSeed(long seed)
Throws UnsupportedOperationException.
|
Methods inherited from class java.util.Random |
Methods inherited from class java.lang.Object |
Methods inherited from interface java.util.random.RandomGenerator |
public static ThreadLocalRandom current |
() |
public void setSeed |
(long seed) |
protected int next |
(int bits) |
public boolean nextBoolean |
() |
public int nextInt |
() |
public int nextInt |
(int bound) |
public int nextInt |
(int origin, int bound) |
public long nextLong |
() |
public long nextLong |
(long bound) |
public long nextLong |
(long origin, long bound) |
public float nextFloat |
() |
The general contract of nextFloat is that one float value, chosen (approximately) uniformly from the range 0.0f (inclusive) to 1.0f (exclusive), is pseudorandomly generated and returned. All 224 possible float values of the form m x 2-24, where m is a positive integer less than 224, are produced with (approximately) equal probability.
public float nextFloat |
(float bound) |
public float nextFloat |
(float origin, float bound) |
public double nextDouble |
() |
The general contract of nextDouble is that one double value, chosen (approximately) uniformly from the range 0.0d (inclusive) to 1.0d (exclusive), is pseudorandomly generated and returned.
public double nextDouble |
(double bound) |
public double nextDouble |
(double origin, double bound) |
public IntStream ints |
(long streamSize) |
A pseudorandom int value is generated as if it's the result of calling the method Random.nextInt().
public IntStream ints |
() |
A pseudorandom int value is generated as if it's the result of calling the method Random.nextInt().
public IntStream ints |
(long streamSize, int randomNumberOrigin, int randomNumberBound) |
A pseudorandom int value is generated as if it's the result of calling the following method with the origin and bound:
int nextInt(int origin, int bound) {
int n = bound - origin;
if (n > 0) {
return nextInt(n) + origin;
}
else { // range not representable as int
int r;
do {
r = nextInt();
} while (r < origin || r >= bound);
return r;
}
}
public IntStream ints |
(int randomNumberOrigin, int randomNumberBound) |
A pseudorandom int value is generated as if it's the result of calling the following method with the origin and bound:
int nextInt(int origin, int bound) {
int n = bound - origin;
if (n > 0) {
return nextInt(n) + origin;
}
else { // range not representable as int
int r;
do {
r = nextInt();
} while (r < origin || r >= bound);
return r;
}
}
public LongStream longs |
(long streamSize) |
A pseudorandom long value is generated as if it's the result of calling the method Random.nextLong().
public LongStream longs |
() |
A pseudorandom long value is generated as if it's the result of calling the method Random.nextLong().
public LongStream longs |
(long streamSize, long randomNumberOrigin, long randomNumberBound) |
A pseudorandom long value is generated as if it's the result of calling the following method with the origin and bound:
long nextLong(long origin, long bound) {
long r = nextLong();
long n = bound - origin, m = n - 1;
if ((n & m) == 0L) // power of two
r = (r & m) + origin;
else if (n > 0L) { // reject over-represented candidates
for (long u = r >>> 1; // ensure nonnegative
u + m - (r = u % n) < 0L; // rejection check
u = nextLong() >>> 1) // retry
;
r += origin;
}
else { // range not representable as long
while (r < origin || r >= bound)
r = nextLong();
}
return r;
}
public LongStream longs |
(long randomNumberOrigin, long randomNumberBound) |
A pseudorandom long value is generated as if it's the result of calling the following method with the origin and bound:
long nextLong(long origin, long bound) {
long r = nextLong();
long n = bound - origin, m = n - 1;
if ((n & m) == 0L) // power of two
r = (r & m) + origin;
else if (n > 0L) { // reject over-represented candidates
for (long u = r >>> 1; // ensure nonnegative
u + m - (r = u % n) < 0L; // rejection check
u = nextLong() >>> 1) // retry
;
r += origin;
}
else { // range not representable as long
while (r < origin || r >= bound)
r = nextLong();
}
return r;
}
public DoubleStream doubles |
(long streamSize) |
A pseudorandom double value is generated as if it's the result of calling the method Random.nextDouble().
public DoubleStream doubles |
() |
A pseudorandom double value is generated as if it's the result of calling the method Random.nextDouble().
public DoubleStream doubles |
(long streamSize, double randomNumberOrigin, double randomNumberBound) |
A pseudorandom double value is generated as if it's the result of calling the following method with the origin and bound:
double nextDouble(double origin, double bound) {
double r = nextDouble();
r = r * (bound - origin) + origin;
if (r >= bound) // correct for rounding
r = Math.nextDown(bound);
return r;
}
public DoubleStream doubles |
(double randomNumberOrigin, double randomNumberBound) |
A pseudorandom double value is generated as if it's the result of calling the following method with the origin and bound:
double nextDouble(double origin, double bound) {
double r = nextDouble();
r = r * (bound - origin) + origin;
if (r >= bound) // correct for rounding
r = Math.nextDown(bound);
return r;
}
|
FlexDoc/Javadoc 2.0 Demo Java Doc |