Class RandomUtils

java.lang.Object
org.apache.commons.lang3.RandomUtils

public class RandomUtils extends Object
Supplements the standard Random class.

Use secure() to get the singleton instance based on SecureRandom() which uses a secure random number generator implementing the default random number algorithm.

Use secureStrong() to get the singleton instance based on SecureRandom.getInstanceStrong() which uses an instance that was selected by using the algorithms/providers specified in the securerandom.strongAlgorithms Security property.

Use insecure() to get the singleton instance based on ThreadLocalRandom.current() which is not cryptographically secure. In addition, instances do not use a cryptographically random seed unless the system property java.util.secureRandomSeed is set to true.

Starting in version 3.17.0, the method secure() uses SecureRandom() instead of SecureRandom.getInstanceStrong(), and adds secureStrong().

Starting in version 3.16.0, this class uses secure() for static methods and adds insecure().

Starting in version 3.15.0, this class uses SecureRandom.getInstanceStrong() for static methods.

Before version 3.15.0, this class used ThreadLocalRandom.current() for static methods, which is not cryptographically secure.

Please note that the Apache Commons project provides a component dedicated to pseudo-random number generation, namely Commons RNG, that may be a better choice for applications with more stringent requirements (performance and/or correctness).

Since:
3.3
See Also: