Package org.uncommons.maths.random
Class RandomDotOrgSeedGenerator
java.lang.Object
org.uncommons.maths.random.RandomDotOrgSeedGenerator
- All Implemented Interfaces:
SeedGenerator
Connects to the random.org
website (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 and other platforms that do not provide /dev/random.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static byte[]
private static final Lock
private static int
private static final int
Random.org does not allow requests for more than 10k integers at once.private static final String
The URL from which the random bytes are retrieved.private static final String
Used to identify the client to the random.org service. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
generateSeed
(int length) Generate a seed value for a random number generator.private void
refreshCache
(int requiredBytes) toString()
-
Field Details
-
BASE_URL
- See Also:
-
RANDOM_URL
The URL from which the random bytes are retrieved.- See Also:
-
USER_AGENT
Used to identify the client to the random.org service. -
MAX_REQUEST_SIZE
private static final int MAX_REQUEST_SIZERandom.org does not allow requests for more than 10k integers at once.- See Also:
-
cacheLock
-
cache
private static byte[] cache -
cacheOffset
private static int cacheOffset
-
-
Constructor Details
-
RandomDotOrgSeedGenerator
public RandomDotOrgSeedGenerator()
-
-
Method Details
-
generateSeed
Generate a seed value for a random number generator.- Specified by:
generateSeed
in interfaceSeedGenerator
- 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.
-
refreshCache
- Parameters:
requiredBytes
- The preferred number of bytes to request from random.org. The implementation may request more and cache the excess (to avoid making lots of small requests). Alternatively, it may request fewer if the required number is greater than that permitted by random.org for a single request.- Throws:
IOException
- If there is a problem downloading the random bits.
-
toString
-