Class ThreadRandom

java.lang.Object
java.lang.ThreadLocal<Random>
cl.obcom.desktopfx.util.ThreadRandom

public final class ThreadRandom extends ThreadLocal<Random>
Provides a Random local to the current running Thread.
  • Method Details

    • initialValue

      protected Random initialValue()
      Returns the current thread's "initial value" for this thread-local variable. This method will be invoked the first time a thread accesses the variable with the ThreadLocal.get() method, unless the thread previously invoked the ThreadLocal.set(T) method, in which case the initialValue method will not be invoked for the thread. Normally, this method is invoked at most once per thread, but it may be invoked again in case of subsequent invocations of ThreadLocal.remove() followed by ThreadLocal.get().
      Overrides:
      initialValue in class ThreadLocal<Random>
      Returns:
      the initial value for this thread-local.
      Throws:
      InternalError - if an error occurs creating the initial value-
    • nextBytes

      public static void nextBytes(byte[] bytes)
      Generates a user-specified number of random bytes.
      Parameters:
      bytes - the array to be filled in with random bytes.
      Throws:
      NullPointerException - if bytes is null.
    • nextInt

      public static int nextInt()
      Returns the next pseudorandom, uniformly distributed integer value.
      Returns:
      the next pseudorandom, uniformly distributed integer value.