Package org.apache.hadoop.crypto.random
Class OpensslSecureRandom
java.lang.Object
java.util.Random
org.apache.hadoop.crypto.random.OpensslSecureRandom
- All Implemented Interfaces:
Serializable,RandomGenerator
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanprotected final intnext(int numBits) Generates an integer containing the user-specified number of random bits (right justified, with leading zeros).voidnextBytes(byte[] bytes) Generates a user-specified number of random bytes.voidsetSeed(long seed) Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLongMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
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:
nextBytesin interfaceRandomGenerator- Overrides:
nextBytesin classRandom- Parameters:
bytes- the array to be filled in with random bytes.
-
setSeed
public void setSeed(long seed) -
next
protected final int next(int numBits) Generates an integer containing the user-specified number of random bits (right justified, with leading zeros).
-