Package cl.obcom.desktopfx.util
Class ThreadRandom
Provides a Random local to the current running Thread.
-
Method Summary
Modifier and TypeMethodDescriptionprotected Random
Returns the current thread's "initial value" for this thread-local variable.static void
nextBytes
(byte[] bytes) Generates a user-specified number of random bytes.static int
nextInt()
Returns the next pseudorandom, uniformly distributed integer value.Methods inherited from class java.lang.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 theinitialValue
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 ofThreadLocal.remove()
followed byThreadLocal.get()
.- Overrides:
initialValue
in 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
- ifbytes
isnull
.
-
nextInt
public static int nextInt()Returns the next pseudorandom, uniformly distributed integer value.- Returns:
- the next pseudorandom, uniformly distributed integer value.
-