class ThreadLocalRandom extends Random
A random number generator isolated to the current thread. Like the
global java.util.Random
generator used by the java.lang.Math
class, a ThreadLocalRandom
is initialized
with an internally generated seed that may not otherwise be
modified. When applicable, use of ThreadLocalRandom
rather
than shared Random
objects in concurrent programs will
typically encounter much less overhead and contention. Use of
ThreadLocalRandom
is particularly appropriate when multiple
tasks (for example, each a ForkJoinTask
) use random numbers
in parallel in thread pools.
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.
- Source
- ThreadLocalRandom.java
- Since
1.7
- Alphabetic
- By Inheritance
- ThreadLocalRandom
- Random
- Serializable
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
+(other: String): String
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to any2stringadd[ThreadLocalRandom] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
->[B](y: B): (ThreadLocalRandom, B)
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to ArrowAssoc[ThreadLocalRandom] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate() @throws( ... )
-
def
doubles(arg0: Double, arg1: Double): DoubleStream
- Definition Classes
- Random
-
def
doubles(arg0: Long, arg1: Double, arg2: Double): DoubleStream
- Definition Classes
- Random
-
def
doubles(): DoubleStream
- Definition Classes
- Random
-
def
doubles(arg0: Long): DoubleStream
- Definition Classes
- Random
-
def
ensuring(cond: (ThreadLocalRandom) ⇒ Boolean, msg: ⇒ Any): ThreadLocalRandom
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to Ensuring[ThreadLocalRandom] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: (ThreadLocalRandom) ⇒ Boolean): ThreadLocalRandom
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to Ensuring[ThreadLocalRandom] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): ThreadLocalRandom
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to Ensuring[ThreadLocalRandom] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): ThreadLocalRandom
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to Ensuring[ThreadLocalRandom] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to StringFormat[ThreadLocalRandom] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
ints(arg0: Int, arg1: Int): IntStream
- Definition Classes
- Random
-
def
ints(arg0: Long, arg1: Int, arg2: Int): IntStream
- Definition Classes
- Random
-
def
ints(): IntStream
- Definition Classes
- Random
-
def
ints(arg0: Long): IntStream
- Definition Classes
- Random
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
longs(arg0: Long, arg1: Long): LongStream
- Definition Classes
- Random
-
def
longs(arg0: Long, arg1: Long, arg2: Long): LongStream
- Definition Classes
- Random
-
def
longs(): LongStream
- Definition Classes
- Random
-
def
longs(arg0: Long): LongStream
- Definition Classes
- Random
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
next(bits: Int): Int
- Attributes
- protected[akka.dispatch.forkjoin]
- Definition Classes
- ThreadLocalRandom → Random
-
def
nextBoolean(): Boolean
- Definition Classes
- Random
-
def
nextBytes(arg0: Array[Byte]): Unit
- Definition Classes
- Random
-
def
nextDouble(least: Double, bound: Double): Double
Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bound (exclusive).
Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bound (exclusive).
- least
the least value returned
- bound
the upper bound (exclusive)
- returns
the next value
- Exceptions thrown
IllegalArgumentException
if least greater than or equal to bound
-
def
nextDouble(n: Double): Double
Returns a pseudorandom, uniformly distributed
double
value between 0 (inclusive) and the specified value (exclusive).Returns a pseudorandom, uniformly distributed
double
value between 0 (inclusive) and the specified value (exclusive).- n
the bound on the random number to be returned. Must be positive.
- returns
the next value
- Exceptions thrown
IllegalArgumentException
if n is not positive
-
def
nextDouble(): Double
- Definition Classes
- Random
-
def
nextFloat(): Float
- Definition Classes
- Random
-
def
nextGaussian(): Double
- Definition Classes
- Random
-
def
nextInt(least: Int, bound: Int): Int
Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bound (exclusive).
Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bound (exclusive).
- least
the least value returned
- bound
the upper bound (exclusive)
- returns
the next value
- Exceptions thrown
IllegalArgumentException
if least greater than or equal to bound
-
def
nextInt(arg0: Int): Int
- Definition Classes
- Random
-
def
nextInt(): Int
- Definition Classes
- Random
-
def
nextLong(least: Long, bound: Long): Long
Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bound (exclusive).
Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bound (exclusive).
- least
the least value returned
- bound
the upper bound (exclusive)
- returns
the next value
- Exceptions thrown
IllegalArgumentException
if least greater than or equal to bound
-
def
nextLong(n: Long): Long
Returns a pseudorandom, uniformly distributed value between 0 (inclusive) and the specified value (exclusive).
Returns a pseudorandom, uniformly distributed value between 0 (inclusive) and the specified value (exclusive).
- n
the bound on the random number to be returned. Must be positive.
- returns
the next value
- Exceptions thrown
IllegalArgumentException
if n is not positive
-
def
nextLong(): Long
- Definition Classes
- Random
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
setSeed(seed: Long): Unit
Throws
UnsupportedOperationException
.Throws
UnsupportedOperationException
. Setting seeds in this generator is not supported.- Definition Classes
- ThreadLocalRandom → Random
- Exceptions thrown
UnsupportedOperationException
always
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
→[B](y: B): (ThreadLocalRandom, B)
- Implicit
- This member is added by an implicit conversion from ThreadLocalRandom to ArrowAssoc[ThreadLocalRandom] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc