Package squidpony.squidmath
Class DistributedRNG
java.lang.Object
squidpony.squidmath.AbstractRNG
squidpony.squidmath.DistributedRNG
- All Implemented Interfaces:
- Serializable,- IRNG,- IStatefulRNG,- RandomnessSource,- StatefulRandomness
public class DistributedRNG extends AbstractRNG implements IStatefulRNG, StatefulRandomness, Serializable
An implementation of 
This uses a
Created by Tommy Ettinger on 11/27/2019.
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.
 This uses a
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.
 Created by Tommy Ettinger on 11/27/2019.
- See Also:
- Serialized Form
- 
Field SummaryFields Modifier and Type Field Description IDistribution.SimpleDistributiondistributionMoonwalkRNGrng
- 
Constructor SummaryConstructors Constructor Description DistributedRNG()DistributedRNG(long state)DistributedRNG(long state, IDistribution.SimpleDistribution distribution)
- 
Method SummaryModifier and Type Method Description DistributedRNGcopy()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.longgetState()Get the current internal state of the StatefulRandomness as a long.intnext(int bits)Get up to 32 bits (inclusive) of random output; the int this produces will not require more thanbitsbits to represent.booleannextBoolean()Get a random bit of state, interpreted as true or false with approximately equal likelihood.doublenextDouble()Gets a random double between 0.0 inclusive and 1.0 exclusive.floatnextFloat()Gets a random float between 0.0f inclusive and 1.0f exclusive.intnextInt()Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).intnextInt(int bound)Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or negative.longnextLong()Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).longnextLong(long bound)Exclusive on bound (which must be positive), with an inner bound of 0.intnextSignedInt(int bound)Returns a random non-negative integer between 0 (inclusive) and the given bound (exclusive), or 0 if the bound is 0.longnextSignedLong(long bound)Exclusive on bound (which may be positive or negative), with an inner bound of 0.voidsetState(long state)Set the current internal state of this StatefulRandomness with a long; this accepts a state of 0 with no issues.SerializabletoSerializable()Gets a view of this IRNG in a way that implementsSerializable, which may simply be this IRNG if it implements Serializable as well as IRNG.Methods inherited from class squidpony.squidmath.AbstractRNGbetween, between, between, getRandomElement, getRandomElement, getRandomElement, nextDouble, nextFloat, randomOrdering, randomOrdering, randomPortion, shuffle, shuffle, shuffle, shuffle, shuffleInPlace, shuffleInPlace, swapMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface squidpony.squidmath.IRNGbetween, between, between, getRandomElement, getRandomElement, getRandomElement, nextDouble, nextFloat, randomOrdering, randomOrdering, randomPortion, shuffle, shuffle, shuffle, shuffle, shuffleInPlace, shuffleInPlace
- 
Field Details
- 
Constructor Details
- 
Method Details- 
nextGet up to 32 bits (inclusive) of random output; the int this produces will not require more thanbitsbits to represent.- Specified by:
- nextin interface- IRNG
- Specified by:
- nextin interface- RandomnessSource
- Specified by:
- nextin class- AbstractRNG
- Parameters:
- bits- an int between 1 and 32, both inclusive
- Returns:
- a random number that fits in the specified number of bits
 
- 
nextIntGet a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).- Specified by:
- nextIntin interface- IRNG
- Specified by:
- nextIntin class- AbstractRNG
- Returns:
- a 32-bit random int.
 
- 
nextLongGet a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive). This implementation has "holes" in its range, numbers that it cannot produce regardless of distribution.- Specified by:
- nextLongin interface- IRNG
- Specified by:
- nextLongin interface- RandomnessSource
- Specified by:
- nextLongin class- AbstractRNG
- Returns:
- a 64-bit random long.
 
- 
nextBooleanGet a random bit of state, interpreted as true or false with approximately equal likelihood.- Specified by:
- nextBooleanin interface- IRNG
- Specified by:
- nextBooleanin class- AbstractRNG
- Returns:
- a random boolean.
 
- 
nextDoubleGets a random double between 0.0 inclusive and 1.0 exclusive. This returns a maximum of 0.9999999999999999 because that is the largest double value that is less than 1.0 .- Specified by:
- nextDoublein interface- IRNG
- Specified by:
- nextDoublein class- AbstractRNG
- Returns:
- a double between 0.0 (inclusive) and 0.9999999999999999 (inclusive)
 
- 
nextFloatGets a random float between 0.0f inclusive and 1.0f exclusive. This returns a maximum of 0.99999994 because that is the largest float value that is less than 1.0f .- Specified by:
- nextFloatin interface- IRNG
- Specified by:
- nextFloatin class- AbstractRNG
- Returns:
- a float between 0f (inclusive) and 0.99999994f (inclusive)
 
- 
nextIntReturns a random non-negative integer below the given bound, or 0 if the bound is 0 or negative.- Specified by:
- nextIntin interface- IRNG
- Overrides:
- nextIntin class- AbstractRNG
- Parameters:
- bound- the upper bound (exclusive)
- Returns:
- the found number
 
- 
nextLongExclusive on bound (which must be positive), with an inner bound of 0. If bound is negative or 0 this always returns 0.- Specified by:
- nextLongin interface- IRNG
- Overrides:
- nextLongin class- AbstractRNG
- Parameters:
- bound- the outer exclusive bound; should be positive, otherwise this always returns 0L
- Returns:
- a random long between 0 (inclusive) and bound (exclusive)
 
- 
nextSignedLongExclusive on bound (which may be positive or negative), with an inner bound of 0. If bound is negative this returns a negative long; if bound is positive this returns a positive long. The bound can even be 0, which will cause this to return 0L every time.- Specified by:
- nextSignedLongin interface- IRNG
- Overrides:
- nextSignedLongin class- AbstractRNG
- Parameters:
- bound- the outer exclusive bound; can be positive or negative
- Returns:
- a random long between 0 (inclusive) and bound (exclusive)
 
- 
nextSignedIntReturns a random non-negative integer between 0 (inclusive) and the given bound (exclusive), or 0 if the bound is 0. The bound can be negative, which will produce 0 or a negative result.- Specified by:
- nextSignedIntin interface- IRNG
- Overrides:
- nextSignedIntin class- AbstractRNG
- Parameters:
- bound- the outer bound (exclusive), can be negative or positive
- Returns:
- the found number
 
- 
copyCreates 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. The copy will not share references with this IRNG, except todistribution, which usually shouldn't change much.- Specified by:
- copyin interface- IRNG
- Specified by:
- copyin interface- RandomnessSource
- Specified by:
- copyin interface- StatefulRandomness
- Specified by:
- copyin class- AbstractRNG
- Returns:
- a copy of this IRNG
 
- 
toSerializableGets a view of this IRNG in a way that implementsSerializable, which may simply be this IRNG if it implements Serializable as well as IRNG.- Specified by:
- toSerializablein interface- IRNG
- Specified by:
- toSerializablein class- AbstractRNG
- Returns:
- a Serializableview of this IRNG or a similar one; may bethis
 
- 
getStateGet the current internal state of the StatefulRandomness as a long.- Specified by:
- getStatein interface- StatefulRandomness
- Returns:
- the current internal state of this object.
 
- 
setStateSet the current internal state of this StatefulRandomness with a long; this accepts a state of 0 with no issues.- Specified by:
- setStatein interface- StatefulRandomness
- Parameters:
- state- a 64-bit long.
 
 
-