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, swap
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
between, between, between, getRandomElement, getRandomElement, getRandomElement, nextDouble, nextFloat, randomOrdering, randomOrdering, randomPortion, shuffle, shuffle, shuffle, shuffle, shuffleInPlace, shuffleInPlace
public 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 IRNG
next
in interface RandomnessSource
next
in class AbstractRNG
bits
- an int between 1 and 32, both inclusivepublic int nextInt()
nextInt
in interface IRNG
nextInt
in class AbstractRNG
public long nextLong()
nextLong
in interface IRNG
nextLong
in interface RandomnessSource
nextLong
in class AbstractRNG
public boolean nextBoolean()
nextBoolean
in interface IRNG
nextBoolean
in class AbstractRNG
public double nextDouble()
nextDouble
in interface IRNG
nextDouble
in class AbstractRNG
public float nextFloat()
nextFloat
in interface IRNG
nextFloat
in class AbstractRNG
public int nextInt(int bound)
nextInt
in interface IRNG
nextInt
in class AbstractRNG
bound
- the upper bound (exclusive)public long nextLong(long bound)
nextLong
in interface IRNG
nextLong
in class AbstractRNG
bound
- the outer exclusive bound; should be positive, otherwise this always returns 0Lpublic long nextSignedLong(long outerBound)
nextSignedLong
in interface IRNG
nextSignedLong
in class AbstractRNG
outerBound
- the outer exclusive bound; can be positive or negativepublic int nextSignedInt(int outerBound)
nextSignedInt
in interface IRNG
nextSignedInt
in class AbstractRNG
outerBound
- the outer bound (exclusive), can be negative or positivepublic DistributedRNG copy()
distribution
, which usually shouldn't change much.copy
in interface RandomnessSource
copy
in interface StatefulRandomness
copy
in class AbstractRNG
public java.io.Serializable toSerializable()
Serializable
, which may simply be this IRNG if it
implements Serializable as well as IRNG.toSerializable
in interface IRNG
toSerializable
in class AbstractRNG
Serializable
view of this IRNG or a similar one; may be this
public long getState()
getState
in interface StatefulRandomness
public void setState(long state)
setState
in interface StatefulRandomness
state
- a 64-bit long.Copyright © Eben Howard 2012–2022. All rights reserved.