Enum RandomDotOrgSeedGenerator

  • All Implemented Interfaces:
    SeedGenerator, Serializable, Comparable<RandomDotOrgSeedGenerator>

    public enum RandomDotOrgSeedGenerator
    extends Enum<RandomDotOrgSeedGenerator>
    implements SeedGenerator

    Connects to random.org's old API (via HTTPS) and downloads a set of random bits to use as seed data. It is generally better to use the DevRandomSeedGenerator where possible, as it should be much quicker. This seed generator is most useful on Microsoft Windows without Cygwin, and other platforms that do not provide /dev/random.

    Random.org collects randomness from atmospheric noise using 9 radios, located at undisclosed addresses in Dublin and Copenhagen and tuned to undisclosed AM/FM frequencies. (The secrecy is intended to help prevent tampering with the output using a well-placed radio transmitter, and the use of AM/FM helps ensure that any such tampering would cause illegal interference with broadcasts and quickly attract regulatory attention.)

    Random.org has two APIs: an old API and a newer JSON-RPC API. Since the new one requires a key obtained from random.org, the old one is used by default. However, if you have a key, you can provide it by calling setApiKey(UUID), and the new API will then be used.

    Note that when using the old API, random.org limits the supply of free random numbers to any one IP address; if you operate from a fixed address (at least if you use IPv4), you can check your quota and buy more. On the new API, the quota is per key rather than per IP, and commercial-use pricing follows a different scheme.

    Author:
    Daniel Dyer (old API), Chris Hennick (new API; refactoring)
    • Enum Constant Detail

      • RANDOM_DOT_ORG_SEED_GENERATOR

        public static final RandomDotOrgSeedGenerator RANDOM_DOT_ORG_SEED_GENERATOR
        This version of the client may make HTTP requests as fast as your computer is capable of sending them. Since it is inherently spammy, it is recommended only when you know your usage is light and/or no other source of randomness will do.
    • Method Detail

      • values

        public static RandomDotOrgSeedGenerator[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (RandomDotOrgSeedGenerator c : RandomDotOrgSeedGenerator.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static RandomDotOrgSeedGenerator valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • setApiKey

        public static void setApiKey​(@Nullable
                                     UUID apiKey)
        Sets the API key. If not null, random.org's JSON API is used. Otherwise, the old API is used.
        Parameters:
        apiKey - An API key obtained from random.org.
      • setProxy

        public static void setProxy​(@Nullable
                                    Proxy proxy)
        Sets the proxy to use to connect to random.org. If null, the JVM default is used.
        Parameters:
        proxy - a proxy, or null for the JVM default
      • setSslSocketFactory

        public static void setSslSocketFactory​(@Nullable
                                               SSLSocketFactory socketFactory)
        Sets the socket factory to use to connect to random.org. If null, the JVM default is used. This method provides flexibility in how the user protects against downgrade attacks such as POODLE and weak cipher suites, even if the random.org connection needs separate handling from connections to other services by the same application.
        Parameters:
        socketFactory - a socket factory, or null for the JVM default
      • generateSeed

        public void generateSeed​(byte[] seed)
                          throws SeedException
        Description copied from interface: SeedGenerator
        Generates a seed value for a random number generator in an existing array.
        Specified by:
        generateSeed in interface SeedGenerator
        Parameters:
        seed - The array that is to be populated with the seed.
        Throws:
        SeedException - If a seed cannot be generated for any reason.
      • generateSeed

        public byte[] generateSeed​(int length)
                            throws SeedException
        Description copied from interface: SeedGenerator
        Generates and returns a seed value for a random number generator as a new array.
        Specified by:
        generateSeed in interface SeedGenerator
        Parameters:
        length - The length of the seed to generate (in bytes).
        Returns:
        A byte array containing the seed data.
        Throws:
        SeedException - If a seed cannot be generated for any reason.