Class RandomDotOrgAnonymousClient

  • All Implemented Interfaces:
    SeedGenerator, Serializable

    public class RandomDotOrgAnonymousClient
    extends WebSeedClient

    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 (or where that device is very slow).

    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 provided to each user by random.org, a client for the old one is still useful for anonymous access. However, if you have a key, you can instead use RandomDotOrgApi2Client.

    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 (original version), Chris Hennick (refactoring)
    See Also:
    Serialized Form
    • Constructor Detail

      • RandomDotOrgAnonymousClient

        public RandomDotOrgAnonymousClient()
    • Method Detail

      • getMaxRequestSize

        protected int getMaxRequestSize()
        Description copied from class: WebSeedClient
        Returns the maximum number of bytes that can be obtained with one request to the service. When a seed larger than this is needed, it is obtained using multiple requests.
        Specified by:
        getMaxRequestSize in class WebSeedClient
        Returns:
        the maximum number of bytes per request
      • downloadBytes

        protected void downloadBytes​(HttpURLConnection connection,
                                     byte[] seed,
                                     int offset,
                                     int length)
                              throws IOException
        Description copied from class: WebSeedClient
        Performs a single request for random bytes.
        Specified by:
        downloadBytes in class WebSeedClient
        Parameters:
        connection - the connection to download from
        seed - the array to save them to
        offset - the first index to save them to in the array
        length - the number of bytes to download
        Throws:
        IOException - if a connection error occurs