Class OpensslSecureRandom

java.lang.Object
java.util.Random
org.apache.hadoop.crypto.random.OpensslSecureRandom
All Implemented Interfaces:
Serializable, RandomGenerator

@Private public class OpensslSecureRandom extends Random
OpenSSL secure random using JNI. This implementation is thread-safe.

If using an Intel chipset with RDRAND, the high-performance hardware random number generator will be used and it's much faster than SecureRandom. If RDRAND is unavailable, default OpenSSL secure random generator will be used. It's still faster and can generate strong random bytes.

See https://wiki.openssl.org/index.php/Random_Numbers See http://en.wikipedia.org/wiki/RdRand

See Also:
  • Constructor Details

    • OpensslSecureRandom

      public OpensslSecureRandom()
  • Method Details

    • isNativeCodeLoaded

      public static boolean isNativeCodeLoaded()
    • nextBytes

      public void nextBytes(byte[] bytes)
      Generates a user-specified number of random bytes. It's thread-safe.
      Specified by:
      nextBytes in interface RandomGenerator
      Overrides:
      nextBytes in class Random
      Parameters:
      bytes - the array to be filled in with random bytes.
    • setSeed

      public void setSeed(long seed)
      Overrides:
      setSeed in class Random
    • next

      protected final int next(int numBits)
      Generates an integer containing the user-specified number of random bits (right justified, with leading zeros).
      Overrides:
      next in class Random
      Parameters:
      numBits - number of random bits to be generated, where 0 <= numBits <= 32.
      Returns:
      int an int containing the user-specified number of random bits (right justified, with leading zeros).