public class DistributedRNG extends AbstractRNG implements IStatefulRNG, StatefulRandomness, java.io.Serializable
IRNG that allows specifying a distribution for all random numbers it produces via a
IDistribution.SimpleDistribution value. You can adapt any IDistribution to a
SimpleDistribution with the static methods in SimpleDistribution, like
IDistribution.SimpleDistribution.fractionalDistribution(IDistribution). If no
distribution is specified, this uses CurvedBoundedDistribution.instance.
MoonwalkRNG internally to handle the number generation that the distribution requests. While you
can call methods on rng that are specific to MoonwalkRNG, many distributions will get multiple random
numbers where a normal RNG would only get one, and this makes the state-jumping features of MoonwalkRNG less useful
here. It's still a fast generator when it comes to generating doubles, which is why it's used here; GWT-oriented
generators would be slower at generating doubles on desktop and many mobile platforms.
| Modifier and Type | Field and Description |
|---|---|
IDistribution.SimpleDistribution |
distribution |
MoonwalkRNG |
rng |
| Constructor and Description |
|---|
DistributedRNG() |
DistributedRNG(long state) |
DistributedRNG(long state,
IDistribution.SimpleDistribution distribution) |
| Modifier and Type | Method and Description |
|---|---|
DistributedRNG |
copy()
Creates a copy of this IRNG; it will generate the same random numbers, given the same calls in order, as this
IRNG at the point copy() is called.
|
long |
getState()
Get the current internal state of the StatefulRandomness as a long.
|
int |
next(int bits)
Get up to 32 bits (inclusive) of random output; the int this produces
will not require more than
bits bits to represent. |
boolean |
nextBoolean()
Get a random bit of state, interpreted as true or false with approximately equal likelihood.
|
double |
nextDouble()
Gets a random double between 0.0 inclusive and 1.0 exclusive.
|
float |
nextFloat()
Gets a random float between 0.0f inclusive and 1.0f exclusive.
|
int |
nextInt()
Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).
|
int |
nextInt(int bound)
Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or
negative.
|
long |
nextLong()
Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).
|
long |
nextLong(long bound)
Exclusive on bound (which must be positive), with an inner bound of 0.
|
int |
nextSignedInt(int outerBound)
Returns a random non-negative integer between 0 (inclusive) and the given bound (exclusive),
or 0 if the bound is 0.
|
long |
nextSignedLong(long outerBound)
Exclusive on bound (which may be positive or negative), with an inner bound of 0.
|
void |
setState(long state)
Set the current internal state of this StatefulRandomness with a long; this accepts a state of 0 with no issues.
|
java.io.Serializable |
toSerializable()
Gets a view of this IRNG in a way that implements
Serializable, which may simply be this IRNG if it
implements Serializable as well as IRNG. |
between, between, between, getRandomElement, getRandomElement, getRandomElement, nextDouble, nextFloat, randomOrdering, randomOrdering, randomPortion, shuffle, shuffle, shuffle, shuffle, shuffleInPlace, shuffleInPlace, swapclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbetween, between, between, getRandomElement, getRandomElement, getRandomElement, nextDouble, nextFloat, randomOrdering, randomOrdering, randomPortion, shuffle, shuffle, shuffle, shuffle, shuffleInPlace, shuffleInPlacepublic IDistribution.SimpleDistribution distribution
public MoonwalkRNG rng
public DistributedRNG()
public DistributedRNG(long state)
public DistributedRNG(long state,
IDistribution.SimpleDistribution distribution)
public final int next(int bits)
bits bits to represent.next in interface IRNGnext in interface RandomnessSourcenext in class AbstractRNGbits - an int between 1 and 32, both inclusivepublic int nextInt()
nextInt in interface IRNGnextInt in class AbstractRNGpublic long nextLong()
nextLong in interface IRNGnextLong in interface RandomnessSourcenextLong in class AbstractRNGpublic boolean nextBoolean()
nextBoolean in interface IRNGnextBoolean in class AbstractRNGpublic double nextDouble()
nextDouble in interface IRNGnextDouble in class AbstractRNGpublic float nextFloat()
nextFloat in interface IRNGnextFloat in class AbstractRNGpublic int nextInt(int bound)
nextInt in interface IRNGnextInt in class AbstractRNGbound - the upper bound (exclusive)public long nextLong(long bound)
nextLong in interface IRNGnextLong in class AbstractRNGbound - the outer exclusive bound; should be positive, otherwise this always returns 0Lpublic long nextSignedLong(long outerBound)
nextSignedLong in interface IRNGnextSignedLong in class AbstractRNGouterBound - the outer exclusive bound; can be positive or negativepublic int nextSignedInt(int outerBound)
nextSignedInt in interface IRNGnextSignedInt in class AbstractRNGouterBound - the outer bound (exclusive), can be negative or positivepublic DistributedRNG copy()
distribution, which usually shouldn't change much.copy in interface RandomnessSourcecopy in interface StatefulRandomnesscopy in class AbstractRNGpublic java.io.Serializable toSerializable()
Serializable, which may simply be this IRNG if it
implements Serializable as well as IRNG.toSerializable in interface IRNGtoSerializable in class AbstractRNGSerializable view of this IRNG or a similar one; may be thispublic long getState()
getState in interface StatefulRandomnesspublic void setState(long state)
setState in interface StatefulRandomnessstate - a 64-bit long.Copyright © Eben Howard 2012–2022. All rights reserved.