Class RandomDotOrgAnonymousClient
- java.lang.Object
-
- io.github.pr0methean.betterrandom.seed.WebSeedClient
-
- io.github.pr0methean.betterrandom.seed.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
-
-
Field Summary
-
Fields inherited from class io.github.pr0methean.betterrandom.seed.WebSeedClient
CLOCK, earliestNextAttempt, JSON_PARSER, lock, userAgent
-
Fields inherited from interface io.github.pr0methean.betterrandom.seed.SeedGenerator
EMPTY_SEED
-
-
Constructor Summary
Constructors Constructor Description RandomDotOrgAnonymousClient()
RandomDotOrgAnonymousClient(WebSeedClientConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
downloadBytes(HttpURLConnection connection, byte[] seed, int offset, int length)
Performs a single request for random bytes.protected URL
getConnectionUrl(int numBytes)
protected int
getMaxRequestSize()
Returns the maximum number of bytes that can be obtained with one request to the service.-
Methods inherited from class io.github.pr0methean.betterrandom.seed.WebSeedClient
checkedGetObject, divideRoundingUp, equals, generateSeed, getProxy, getResponseReader, getRetryDelayMs, getSocketFactory, hashCode, isWorthTrying, modRange1ToM, openConnection, parseJsonResponse
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.pr0methean.betterrandom.seed.SeedGenerator
generateSeed
-
-
-
-
Constructor Detail
-
RandomDotOrgAnonymousClient
public RandomDotOrgAnonymousClient(WebSeedClientConfiguration configuration)
-
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 classWebSeedClient
- Returns:
- the maximum number of bytes per request
-
getConnectionUrl
protected URL getConnectionUrl(int numBytes)
- Specified by:
getConnectionUrl
in classWebSeedClient
-
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 classWebSeedClient
- Parameters:
connection
- the connection to download fromseed
- the array to save them tooffset
- the first index to save them to in the arraylength
- the number of bytes to download- Throws:
IOException
- if a connection error occurs
-
-