public final class RandomUtil extends Object
SecureRandom and provides new
instances of SecureRandom.public static int nextInt()
public static long nextLong()
public static SecureRandom newSecureRandom()
SecureRandom.
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"
SecureRandom.Copyright © 2024. All rights reserved.