- java.lang.Object
-
- com.github.f4b6a3.uuid.util.internal.RandomUtil
-
public final class RandomUtil extends Object
Utility class that wraps a sharedSecureRandomand provides new instances ofSecureRandom.
-
-
Field Summary
Fields Modifier and Type Field Description protected static SecureRandomSHARED_RANDOM
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SecureRandomnewSecureRandom()Returns a new instance ofSecureRandom.static intnextInt()static longnextLong()
-
-
-
Field Detail
-
SHARED_RANDOM
protected static final SecureRandom SHARED_RANDOM
-
-
Method Detail
-
nextInt
public static int nextInt()
-
nextLong
public static long nextLong()
-
newSecureRandom
public static SecureRandom newSecureRandom()
Returns a new instance ofSecureRandom.It tries to create an instance with the algorithm name specified in the system property `uuidcreator.securerandom` or in the environment variable `UUIDCREATOR_SECURERANDOM`. If the algorithm name is not supported by the runtime, it returns an instance with the default algorithm.
It can be useful to make use of SHA1PRNG or DRBG as a non-blocking source of random bytes. The SHA1PRNG algorithm is default on operating systems that don't have '/dev/random', e.g., on Windows. The DRBG algorithm is available in JDK 9+.
To control the algorithm used by this method, use the system property `uuidcreator.securerandom` or the environment variable `UUIDCREATOR_SECURERANDOM` as in examples below.
System property:
# Use the the algorithm SHA1PRNG for SecureRandom -Duuidcreator.securerandom="SHA1PRNG" # Use the the algorithm DRBG for SecureRandom (JDK9+) -Duuidcreator.securerandom="DRBG"Environment variable:
# Use the the algorithm SHA1PRNG for SecureRandom export UUIDCREATOR_SECURERANDOM="SHA1PRNG" # Use the the algorithm DRBG for SecureRandom (JDK9+) export UUIDCREATOR_SECURERANDOM="DRBG"- Returns:
- a new
SecureRandom.
-
-