Package com.github.tommyettinger.random
Class ReverseWrapper
java.lang.Object
java.util.Random
com.github.tommyettinger.random.EnhancedRandom
com.github.tommyettinger.random.ReverseWrapper
- All Implemented Interfaces:
Externalizable,Serializable,RandomGenerator
A wrapper around a different
EnhancedRandom object that runs it in reverse, calling
EnhancedRandom.previousLong() instead anywhere nextLong() would be called.
This can be useful to reverse a sequence of calls made to the wrapped generator earlier; the reversed
calls have to happen in reverse order to undo an operation such as a shuffle, typically.
Calling previousLong() is typically not as fast as nextLong(), but usually not by any large degree.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a ReverseWrapper that wraps a DistinctRandom with a random seed.ReverseWrapper(long seed) Creates a ReverseWrapper that wraps a DistinctRandom created withDistinctRandom(long).ReverseWrapper(EnhancedRandom toWrap) This does not copytoWrap, and uses a reference as-is, so this can be useful to reverse some series of calls made earlier to toWrap in a forward direction.ReverseWrapper(ReverseWrapper other) The copy constructor. -
Method Summary
Modifier and TypeMethodDescription<T extends CharSequence & Appendable>
TappendSerialized(T sb, com.github.tommyettinger.digital.Base base) Serializes the current state of this EnhancedRandom and appends it to an Appendable CharSequence (such as a StringBuilder), which may be used byEnhancedRandom.stringDeserialize(String)to load this state at another time.copy()Creates a new EnhancedRandom with identical states to this one, so if the same EnhancedRandom methods are called on this object and its copy (in the same order), the same outputs will be produced.booleanReturnswrapped.getMinimumPeriod().longgetSelectedState(int selection) Gets a selected state value from this EnhancedRandom.intGets the number of possible state variables that can be selected withgetSelectedState(int)orsetSelectedState(int, long).getTag()Gets the tag used to identify this type of EnhancedRandom, as a String.inthashCode()booleanReturnswrapped.mainlyGeneratesInt().intnextInt()Returns the previous pseudorandom, uniformly distributedintvalue from the wrapped random number generator's sequence.longnextLong()Returns the previous pseudorandom, uniformly distributedlongvalue from the wrapped random number generator's sequence.intDelegates to theEnhancedRandom.nextInt()method of the wrapped generator; this is the counterpart to hownextInt()here delegates to theEnhancedRandom.previousInt()()} method of the wrapped generator.longDelegates to theEnhancedRandom.nextLong()method of the wrapped generator; this is the counterpart to hownextLong()here delegates to theEnhancedRandom.previousLong()method of the wrapped generator.voidThe object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.voidsetSeed(long seed) Sets the seed of this random number generator using a singlelongseed.voidsetSelectedState(int selection, long value) Sets a selected state value to the given longvalue.voidsetState(long state) Sets each state variable to the givenstate.voidsetState(long... states) Sets all state variables to alternating values chosen fromstates.voidsetState(long stateA, long stateB) Sets each state variable to eitherstateAorstateB, alternating.voidsetState(long stateA, long stateB, long stateC) Sets each state variable tostateA,stateB, orstateC, alternating.voidsetState(long stateA, long stateB, long stateC, long stateD) Sets each state variable tostateA,stateB,stateC, orstateD, alternating.voidsetState(long stateA, long stateB, long stateC, long stateD, long stateE) Sets each state variable tostateA,stateB,stateC, orstateD, alternating.voidsetWrapped(EnhancedRandom wrapped) voidshuffle(boolean[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(boolean[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(byte[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(byte[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(char[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(char[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(double[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(double[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(float[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(float[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(int[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(int[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(long[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(long[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(short[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.voidshuffle(short[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.<T> voidShuffles the given List in-place pseudo-randomly, using this to determine how to shuffle.<T> voidShuffles a section of the given List in-place pseudo-randomly, using this to determine how to shuffle.<T> voidshuffle(T[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.<T> voidshuffle(T[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.longskip(long advance) Delegates to theEnhancedRandom.skip(long)method if the wrapped generator, but passes it-advanceinstead of advance without changes.stringDeserialize(String data, com.github.tommyettinger.digital.Base base) Given a String in the format produced bystringSerialize(Base), and the sameBaseused by the serialization, this will attempt to set this EnhancedRandom object to match the state in the serialized data.stringSerialize(com.github.tommyettinger.digital.Base base) Serializes the current state of this EnhancedRandom to a String that can be used byEnhancedRandom.stringDeserialize(String)to load this state at another time.toString()voidNeeds the type ofwrappedregistered.Methods inherited from class com.github.tommyettinger.random.EnhancedRandom
appendSerialized, areEqual, fixGamma, fixGamma, lcm, maxDoubleOf, maxFloatOf, maxIntOf, maxLongOf, minDoubleOf, minFloatOf, minIntOf, minLongOf, next, nextBoolean, nextBoolean, nextBytes, nextDouble, nextDouble, nextDouble, nextExclusiveDouble, nextExclusiveDouble, nextExclusiveDouble, nextExclusiveDoubleEquidistant, nextExclusiveFloat, nextExclusiveFloat, nextExclusiveFloat, nextExclusiveFloatEquidistant, nextExclusiveSignedDouble, nextExclusiveSignedFloat, nextExponential, nextFloat, nextFloat, nextFloat, nextGaussian, nextGaussian, nextInclusiveDouble, nextInclusiveDouble, nextInclusiveDouble, nextInclusiveFloat, nextInclusiveFloat, nextInclusiveFloat, nextInt, nextInt, nextLong, nextLong, nextSign, nextSignedInt, nextSignedInt, nextSignedLong, nextSignedLong, nextTriangular, nextTriangular, nextTriangular, nextTriangular, nextUnsignedInt, probit, randomElement, randomElement, rateGamma, seedFromMath, setState, setWith, stringDeserialize, stringSerializeMethods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longsMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.random.RandomGenerator
isDeprecated
-
Field Details
-
wrapped
-
-
Constructor Details
-
ReverseWrapper
public ReverseWrapper()Creates a ReverseWrapper that wraps a DistinctRandom with a random seed. -
ReverseWrapper
public ReverseWrapper(long seed) Creates a ReverseWrapper that wraps a DistinctRandom created withDistinctRandom(long).- Parameters:
seed- the seed that will be used for the wrapped DistinctRandom
-
ReverseWrapper
This does not copytoWrap, and uses a reference as-is, so this can be useful to reverse some series of calls made earlier to toWrap in a forward direction.- Parameters:
toWrap- a non-null EnhancedRandom, preferably not also a wrapper
-
ReverseWrapper
The copy constructor.- Parameters:
other- a non-null ReverseWrapper; itswrapped EnhancedRandommust also be non-null.
-
-
Method Details
-
getWrapped
-
setWrapped
-
getStateCount
public int getStateCount()Gets the number of possible state variables that can be selected withgetSelectedState(int)orsetSelectedState(int, long). This defaults to returning 0, making no state variable available for reading or writing. An implementation that has only onelongstate, likeDistinctRandomgenerator, should return1. A generator that permits setting two differentlongvalues, likeLaserRandom, should return2. Much larger values are possible for types like the Mersenne Twister or some CMWC generators.- Overrides:
getStateCountin classEnhancedRandom- Returns:
- the non-negative number of selections possible for state variables
-
getTag
Gets the tag used to identify this type of EnhancedRandom, as a String. This tag should be unique, and for uniformity purposes, all tags used in this library are 4 characters long. User-defined tags should have a different length.- Specified by:
getTagin classEnhancedRandom- Returns:
- a unique String identifier for this type of EnhancedRandom; usually 4 chars long.
-
mainlyGeneratesInt
public boolean mainlyGeneratesInt()Returnswrapped.mainlyGeneratesInt().- Overrides:
mainlyGeneratesIntin classEnhancedRandom- Returns:
- whatever
wrapped.mainlyGeneratesInt()returns - See Also:
-
getMinimumPeriod
Returnswrapped.getMinimumPeriod().- Overrides:
getMinimumPeriodin classEnhancedRandom- Returns:
- whatever
wrapped.getMinimumPeriod()returns
-
setSeed
public void setSeed(long seed) Sets the seed of this random number generator using a singlelongseed. This should behave exactly the same as if a new object of this type was created with the constructor that takes a singlelongvalue. This does not necessarily assign the state variable(s) of the implementation with the exact contents of seed, sogetSelectedState(int)should not be expected to returnseedafter this, though it may. If this implementation has more than onelongof state, then the expectation is that none of those state variables will be exactly equal toseed(almost all the time).- Specified by:
setSeedin classEnhancedRandom- Parameters:
seed- the initial seed
-
getSelectedState
public long getSelectedState(int selection) Gets a selected state value from this EnhancedRandom. The number of possible selections is up to the implementing class, and is accessible viagetStateCount(), but negative values forselectionare typically not tolerated. This should return the exact value of the selected state, assuming it is implemented. The default implementation throws an UnsupportedOperationException, and implementors only have to allow reading the state if they choose to implement this differently. If this method is intended to be used,getStateCount()must also be implemented.- Overrides:
getSelectedStatein classEnhancedRandom- Parameters:
selection- used to select which state variable to get; generally non-negative- Returns:
- the exact value of the selected state
-
setSelectedState
public void setSelectedState(int selection, long value) Sets a selected state value to the given longvalue. The number of possible selections is up to the implementing class, but negative values forselectionare typically not tolerated. Implementors are permitted to changevalueif it is not valid, but they should not alter it if it is valid. The public implementation callssetSeed(long)withvalue, which doesn't need changing if the generator has one state that is set verbatim by setSeed(). Otherwise, this method should be implemented whengetSelectedState(int)is and the state is allowed to be set by users. Having accurate ways to get and set the full state of a random number generator makes it much easier to serialize and deserialize that class.- Overrides:
setSelectedStatein classEnhancedRandom- Parameters:
selection- used to select which state variable to set; generally non-negativevalue- the exact value to use for the selected state, if valid
-
setState
public void setState(long state) Sets each state variable to the givenstate. IfgetStateCount()is 1, then this should set the whole state to the given value usingsetSelectedState(int, long). If getStateCount() is more than 1, then all states will be set in the same way (using setSelectedState(), all tostate).- Overrides:
setStatein classEnhancedRandom- Parameters:
state- the long value to use for each state variable
-
setState
public void setState(long stateA, long stateB) Sets each state variable to eitherstateAorstateB, alternating. This usessetSelectedState(int, long)to set the values. If there is one state variable (getStateCount()is 1), then this only sets that state variable to stateA. If there are two state variables, the first is set to stateA, and the second to stateB. If there are more, it reuses stateA, then stateB, then stateA, and so on until all variables are set.- Overrides:
setStatein classEnhancedRandom- Parameters:
stateA- the long value to use for states at index 0, 2, 4, 6...stateB- the long value to use for states at index 1, 3, 5, 7...
-
setState
public void setState(long stateA, long stateB, long stateC) Sets each state variable tostateA,stateB, orstateC, alternating. This usessetSelectedState(int, long)to set the values. If there is one state variable (getStateCount()is 1), then this only sets that state variable to stateA. If there are two state variables, the first is set to stateA, and the second to stateB. With three state variables, the first is set to stateA, the second to stateB, and the third to stateC. If there are more, it reuses stateA, then stateB, then stateC, then stateA, and so on until all variables are set.- Overrides:
setStatein classEnhancedRandom- Parameters:
stateA- the long value to use for states at index 0, 3, 6, 9...stateB- the long value to use for states at index 1, 4, 7, 10...stateC- the long value to use for states at index 2, 5, 8, 11...
-
setState
public void setState(long stateA, long stateB, long stateC, long stateD) Sets each state variable tostateA,stateB,stateC, orstateD, alternating. This usessetSelectedState(int, long)to set the values. If there is one state variable (getStateCount()is 1), then this only sets that state variable to stateA. If there are two state variables, the first is set to stateA, and the second to stateB. With three state variables, the first is set to stateA, the second to stateB, and the third to stateC. With four state variables, the first is set to stateA, the second to stateB, the third to stateC, and the fourth to stateD. If there are more, it reuses stateA, then stateB, then stateC, then stateD, then stateA, and so on until all variables are set.- Overrides:
setStatein classEnhancedRandom- Parameters:
stateA- the long value to use for states at index 0, 4, 8, 12...stateB- the long value to use for states at index 1, 5, 9, 13...stateC- the long value to use for states at index 2, 6, 10, 14...stateD- the long value to use for states at index 3, 7, 11, 15...
-
setState
public void setState(long stateA, long stateB, long stateC, long stateD, long stateE) Sets each state variable tostateA,stateB,stateC, orstateD, alternating. This usessetSelectedState(int, long)to set the values. If there is one state variable (getStateCount()is 1), then this only sets that state variable to stateA. If there are two state variables, the first is set to stateA, and the second to stateB. With three state variables, the first is set to stateA, the second to stateB, and the third to stateC. With four state variables, the first is set to stateA, the second to stateB, the third to stateC, and the fourth to stateD. If there are more, it reuses stateA, then stateB, then stateC, then stateD, then stateA, and so on until all variables are set.- Overrides:
setStatein classEnhancedRandom- Parameters:
stateA- the long value to use for states at index 0, 5, 10, 15...stateB- the long value to use for states at index 1, 6, 11, 16...stateC- the long value to use for states at index 2, 7, 12, 17...stateD- the long value to use for states at index 3, 8, 13, 18...stateE- the long value to use for states at index 4, 9, 14, 19...
-
setState
public void setState(long... states) Sets all state variables to alternating values chosen fromstates. If states is empty, then this does nothing, and leaves the current generator unchanged. This works for generators with anygetStateCount(), but may allocate an array if states is used as a varargs (you can pass an existing array without needing to allocate). This usessetSelectedState(int, long)to change the states.- Overrides:
setStatein classEnhancedRandom- Parameters:
states- an array or varargs of long values to use as states
-
nextLong
public long nextLong()Returns the previous pseudorandom, uniformly distributedlongvalue from the wrapped random number generator's sequence. The general contract ofnextLongis that onelongvalue is pseudorandomly generated and returned.- Specified by:
nextLongin interfaceRandomGenerator- Specified by:
nextLongin classEnhancedRandom- Returns:
- the previous pseudorandom, uniformly distributed
longvalue from the wrapped random number generator's sequence
-
nextInt
public int nextInt()Returns the previous pseudorandom, uniformly distributedintvalue from the wrapped random number generator's sequence. The general contract ofnextIntis that oneintvalue is pseudorandomly generated and returned. All 232 possibleintvalues are produced with (approximately) equal probability.- Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classEnhancedRandom- Returns:
- the previous pseudorandom, uniformly distributed
intvalue from the wrapped random number generator's sequence
-
previousLong
public long previousLong()Delegates to theEnhancedRandom.nextLong()method of the wrapped generator; this is the counterpart to hownextLong()here delegates to theEnhancedRandom.previousLong()method of the wrapped generator.- Overrides:
previousLongin classEnhancedRandom- Returns:
- the number that
wrapped.nextLong()would produce
-
previousInt
public int previousInt()Delegates to theEnhancedRandom.nextInt()method of the wrapped generator; this is the counterpart to hownextInt()here delegates to theEnhancedRandom.previousInt()()} method of the wrapped generator.- Overrides:
previousIntin classEnhancedRandom- Returns:
- the number that
wrapped.nextLong()would produce
-
skip
public long skip(long advance) Delegates to theEnhancedRandom.skip(long)method if the wrapped generator, but passes it-advanceinstead of advance without changes. This makes it skip in the reverse direction.- Overrides:
skipin classEnhancedRandom- Parameters:
advance- Number of future generations to skip over; can be negative to backtrack, 0 gets the most-recently-generated number- Returns:
- the random long generated after skipping forward or backwards by
advancenumbers
-
shuffle
public void shuffle(long[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(byte[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(int[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(short[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(float[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(double[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(boolean[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(char[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public <T> void shuffle(T[] items, int offset, int length) Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle. Similarly to hownextLong()uses the wrapped generator'sEnhancedRandom.previousLong(), this shuffles in reverse order. This allows you to shuffle an array using one of the wrapped generator's shuffle() methods, then later undo that shuffle by using a ReverseWrapper's shuffle method.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
shuffle
public void shuffle(int[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an int array; must be non-null
-
shuffle
public void shuffle(long[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a long array; must be non-null
-
shuffle
public void shuffle(float[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a float array; must be non-null
-
shuffle
public void shuffle(char[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a char array; must be non-null
-
shuffle
public void shuffle(byte[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a byte array; must be non-null
-
shuffle
public void shuffle(double[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a double array; must be non-null
-
shuffle
public void shuffle(short[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a short array; must be non-null
-
shuffle
public void shuffle(boolean[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a boolean array; must be non-null
-
shuffle
public <T> void shuffle(T[] items) Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- an array of some reference type; must be non-null but may contain null items
-
shuffle
Shuffles the given List in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a List of some typeT; must be non-null but may contain null items
-
shuffle
Shuffles a section of the given List in-place pseudo-randomly, using this to determine how to shuffle.- Overrides:
shufflein classEnhancedRandom- Parameters:
items- a List of some typeT; must be non-null but may contain null itemsoffset- the index of the first element of the array that can be shuffledlength- the length of the section to shuffle
-
copy
Creates a new EnhancedRandom with identical states to this one, so if the same EnhancedRandom methods are called on this object and its copy (in the same order), the same outputs will be produced. This is not guaranteed to copy the inherited state of any parent class, so if you call methods that are only implemented by a superclass (likeRandom) and not this one, the results may differ.- Specified by:
copyin classEnhancedRandom- Returns:
- a deep copy of this EnhancedRandom.
-
stringSerialize
Serializes the current state of this EnhancedRandom to a String that can be used byEnhancedRandom.stringDeserialize(String)to load this state at another time.- Overrides:
stringSerializein classEnhancedRandom- Parameters:
base- which Base to use, from the "digital" library, such asBase.BASE10- Returns:
- a String storing all data from the EnhancedRandom part of this generator
-
appendSerialized
public <T extends CharSequence & Appendable> T appendSerialized(T sb, com.github.tommyettinger.digital.Base base) Description copied from class:EnhancedRandomSerializes the current state of this EnhancedRandom and appends it to an Appendable CharSequence (such as a StringBuilder), which may be used byEnhancedRandom.stringDeserialize(String)to load this state at another time. May use anyBase;Base.BASE10andBase.BASE16are the most intuitive, butBase.SIMPLE64and especiallyBase.BASE90will be more compact.- Overrides:
appendSerializedin classEnhancedRandom- Type Parameters:
T- any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, or CharBuffer- Parameters:
sb- an Appendable CharSequence that will be modifiedbase- which Base to use, from the "digital" library, such asBase.BASE10- Returns:
sb, for chaining
-
stringDeserialize
Given a String in the format produced bystringSerialize(Base), and the sameBaseused by the serialization, this will attempt to set this EnhancedRandom object to match the state in the serialized data. This only works if this EnhancedRandom is the same implementation that was serialized, and also needs the Bases to be identical. Returns this EnhancedRandom, after possibly changing its state.- Overrides:
stringDeserializein classEnhancedRandom- Parameters:
data- a String probably produced bystringSerialize(Base)base- which Base to use, from the "digital" library, such asBase.BASE10- Returns:
- this, after setting its state
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
readExternal
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.- Specified by:
readExternalin interfaceExternalizable- Overrides:
readExternalin classEnhancedRandom- Parameters:
in- the stream to read data from in order to restore the object- Throws:
IOException- if I/O errors occurClassNotFoundException
-
writeExternal
Needs the type ofwrappedregistered.- Specified by:
writeExternalin interfaceExternalizable- Overrides:
writeExternalin classEnhancedRandom- Parameters:
out- the stream to write the object to- Throws:
IOException- Includes any I/O exceptions that may occur
-