Packages

c

akka.dispatch.forkjoin

ThreadLocalRandom

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

Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ThreadLocalRandom
  2. Random
  3. Serializable
  4. AnyRef
  5. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. def doubles(arg0: Double, arg1: Double): DoubleStream
    Definition Classes
    Random
  2. def doubles(arg0: Long, arg1: Double, arg2: Double): DoubleStream
    Definition Classes
    Random
  3. def doubles(): DoubleStream
    Definition Classes
    Random
  4. def doubles(arg0: Long): DoubleStream
    Definition Classes
    Random
  5. def ints(arg0: Int, arg1: Int): IntStream
    Definition Classes
    Random
  6. def ints(arg0: Long, arg1: Int, arg2: Int): IntStream
    Definition Classes
    Random
  7. def ints(): IntStream
    Definition Classes
    Random
  8. def ints(arg0: Long): IntStream
    Definition Classes
    Random
  9. def longs(arg0: Long, arg1: Long): LongStream
    Definition Classes
    Random
  10. def longs(arg0: Long, arg1: Long, arg2: Long): LongStream
    Definition Classes
    Random
  11. def longs(): LongStream
    Definition Classes
    Random
  12. def longs(arg0: Long): LongStream
    Definition Classes
    Random
  13. def nextBoolean(): Boolean
    Definition Classes
    Random
  14. def nextBytes(arg0: Array[Byte]): Unit
    Definition Classes
    Random
  15. 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

  16. 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

  17. def nextDouble(): Double
    Definition Classes
    Random
  18. def nextFloat(): Float
    Definition Classes
    Random
  19. def nextGaussian(): Double
    Definition Classes
    Random
  20. 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

  21. def nextInt(arg0: Int): Int
    Definition Classes
    Random
  22. def nextInt(): Int
    Definition Classes
    Random
  23. 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

  24. 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

  25. def nextLong(): Long
    Definition Classes
    Random
  26. 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