Random Generators
Last updated
Last updated
This page contains recommendations for generating random values.
Do not use standard pseudo-random number generators, such as those used in mathematics to generate pseudo-random numbers.
Make sure the seed that is used to initialize a generator has enough entropy.
Periodically reinitialize seeds.
Use only cryptographically strong random generators to produce random values, see the section.
Use the package to generate cryptographically strong random values in Go.
Use the class to generate cryptographically strong random values.
Starting with JDK8, use SecureRandom.getInstanceStrong()
to get a SecureRandom
instance that implements a strong generation algorithm. For a UNIX-like OS, the default strong generation algorithm is , which is based on /dev/random
. As a result, SecureRandom.getInstanceStrong()
will return a SecureRandom
implementation that can block a thread when the generateSeed
or nextBytes
methods are called. Use to avoid possible thread blocking.
For older versions of the JDK for UNIX-like OS, create a SecureRandom
instance using the default constructor. However, in this case, calling the generateSeed
method may cause thread blocking. For Windows, use .
Use the package to generate cryptographically strong random values.
Use the package to generate cryptographically strong random values.