Class HighEntropyRandomNumberGenerator

  • All Implemented Interfaces:
    Serializable, DoubleSupplier, RandomNumberGenerator, RandomNumberGenerator1D

    public class HighEntropyRandomNumberGenerator
    extends Object
    implements RandomNumberGenerator1D
    Wrapper class for java.security.SecureRandom. Usage of this class is not recommended for normal operations. There are reported cases in the literature where some pseudorandom number generators might fail in heavily multithreaded applications and lose their statistical properties. This class wraps a cryptography grade RNG based on the system entropy pool (eg. /dev/random on *nix systems) which does not suffer from the same issue. Performance is up to 30x slower than a regular software based PRNG.
    Version:
    1.0
    Author:
    Luca Bressan
    See Also:
    Serialized Form
    • Constructor Detail

      • HighEntropyRandomNumberGenerator

        public HighEntropyRandomNumberGenerator()
      • HighEntropyRandomNumberGenerator

        public HighEntropyRandomNumberGenerator​(SecureRandom secureRandomNumberGenerator)
        This constructor accepts an object from classes that extend java.security.SecureRandom. It is meant to provide a way to integrate hardware RNG functionality or as a clone constructor. You should supply an object instantiating the extending class that uses the JNI to achieve the desired functionality.
        Parameters:
        secureRandomNumberGenerator - the object that will be wrapped.
    • Method Detail

      • nextDouble

        public double nextDouble()
        Returns the next random number in the sequence.
        Specified by:
        nextDouble in interface RandomNumberGenerator1D
        Returns:
        the next random number in the sequence.
      • nextDoubleFast

        public double nextDoubleFast()
        Description copied from interface: RandomNumberGenerator1D
        Possibly faster, non-thread safe implementation returning the next double value of this random number generator. The user of this method has to ensure synchronization if this generator is shared by different threads.
        Specified by:
        nextDoubleFast in interface RandomNumberGenerator1D
        Returns:
        The next double value of this random number generator