|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.Rnd
public final class Rnd
Provides random number sources to be shared across the system. The sources provided are static variables all extending java.util.Random.
Reseeding is either not allowed (throws an exception), or in the spirit of SecureRandom guarantees not to reduce randomness, so these generators can be safely shared.
The sources are partially seeded from time of day or some equivalent.
Using these shared sources helps:
| Field Summary | |
|---|---|
static java.util.Random |
fastRnd
A fast random number generator (compared to goodRnd). |
static java.security.SecureRandom |
goodRnd
Our good-but-slow random number source. |
| Constructor Summary | |
|---|---|
private |
Rnd()
Don't allow creation of instances. |
| Method Summary |
|---|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.security.SecureRandom goodRnd
We will take whatever default generator is available.
We allow the generator to seed itself on first use, hopefully with some genuine entropy.
We make this generator available to all comers, but they should probably not reseed it, just get random values from it. (However, a SecureRandom generator is not completely reset by being reseeded, ie ``is guaranteed not to have its randomness reduced'' by being reseeded, so even reseeding probably does not matter too much.)
Note that this generator can be relatively slow, taking circa 30s--60s to initialise on an SS5/Cycle5-155MHz (oolong.exnet.com, 1999/12/28, no /dev/random).
public static final java.util.Random fastRnd
We allow attempts to reseed this generator, but the reseed value is combined with bits from goodRnd which should make this safe to share and prevents this sequence ever getting 'less' random.
This generator is initially seeded from the time to ensure that we get off to a unique-ish start. On subsequent reseeds will use goodRnd to ensure unpredictability. This should allow for a fast start-up and overall decent behaviour.
We force reseeding from goodRnd often enough (more than 1 once every sqrt(n) samples, where n is the sequence length of the generator) to avoid "drawing from an urn without replacement" behaviour. For java.util.Random the sequence length is ~2^48, so we reseed from goodRnd at most every 2^24 calls to the internal next() generator routine. We do this infrequently enough to keep the amortised cost-per-call low, however.
| Constructor Detail |
|---|
private Rnd()
|
DHD Multimedia Gallery V1.60.69 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||