Class ThreadRandom
Provides a Random local to the current running Thread.
-
Method Summary
Modifier and TypeMethodDescriptionprotected RandomReturns the current thread's "initial value" for this thread-local variable.static voidnextBytes(byte[] bytes) Generates a user-specified number of random bytes.static intnextInt()Returns the next pseudorandom, uniformly distributed integer value.Methods inherited from class ThreadLocal
get, remove, set, withInitial
-
Method Details
-
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 theThreadLocal.get()method, unless the thread previously invoked theThreadLocal.set(T)method, in which case theinitialValuemethod 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 ofThreadLocal.remove()followed byThreadLocal.get().- Overrides:
initialValuein classThreadLocal<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- ifbytesisnull.
-
nextInt
public static int nextInt()Returns the next pseudorandom, uniformly distributed integer value.- Returns:
- the next pseudorandom, uniformly distributed integer value.
-