Class XoshiroStarPhi32RNG

java.lang.Object
java.util.Random
com.github.tommyettinger.random.EnhancedRandom
com.github.yellowstonegames.old.v300.LegacyRandom
com.github.yellowstonegames.old.v300.XoshiroStarPhi32RNG
All Implemented Interfaces:
Externalizable, Serializable, RandomGenerator

public class XoshiroStarPhi32RNG extends LegacyRandom
See Also:
  • Nested Class Summary

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected int
     
    protected int
     
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new generator seeded using four calls to Math.random().
    Constructs this XoshiroStarPhi32RNG by dispersing the bits of seed using setSeed(int) across the four parts of state this has.
    XoshiroStarPhi32RNG(int stateA, int stateB, int stateC, int stateD)
    Constructs this XoshiroStarPhi32RNG by calling setState(int, int, int, int) on stateA and stateB as given; see that method for the specific details (the states are kept as-is unless they are all 0).
    Constructs this XoshiroStarPhi32RNG by dispersing the bits of seed using setSeed(long) across the four parts of state this has.
  • Method Summary

    Modifier and Type
    Method
    Description
    Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the copy, both will generate the same sequence of random numbers from the point copy() was called.
    boolean
     
    long
    getSelectedState(int selection)
     
    int
     
    int
     
    int
     
    int
     
    int
     
     
    int
     
    int
    next(int bits)
     
    int
    Can return any int, positive or negative, of any size permissible in a 32-bit signed integer.
    long
     
    void
    setSeed(int seed)
    Sets the state of this generator using one int, running it through a GWT-compatible variant of SplitMix32 four times to get four ints of state, all guaranteed to be different.
    void
    setSeed(long seed)
    Sets the state of this generator using one long, running it through a GWT-compatible variant of SplitMix32 four times to get four ints of state, guaranteed to repeat a state no more than two times.
    void
    setSelectedState(int selection, long value)
     
    void
    setState(int stateA, int stateB, int stateC, int stateD)
    Sets the current internal state of this XoshiroStarPhi32RNG with four ints, where each can be any int unless they are all 0 (which will be treated as if stateA is 1 and the rest are 0).
    void
    setStateA(int stateA)
    Sets the first part of the state to the given int.
    void
    setStateB(int stateB)
    Sets the second part of the state to the given int.
    void
    setStateC(int stateC)
    Sets the third part of the state to the given int.
    void
    setStateD(int stateD)
    Sets the second part of the state to the given int.
     

    Methods inherited from class com.github.tommyettinger.random.EnhancedRandom

    appendSerialized, appendSerialized, areEqual, fixGamma, fixGamma, getMinimumPeriod, lcm, mainlyGeneratesInt, maxDoubleOf, maxFloatOf, maxIntOf, maxLongOf, minDoubleOf, minFloatOf, minIntOf, minLongOf, nextBoolean, nextBoolean, nextBytes, nextDouble, nextDouble, nextExclusiveDouble, nextExclusiveDouble, nextExclusiveDouble, nextExclusiveDoubleEquidistant, nextExclusiveFloat, nextExclusiveFloat, nextExclusiveFloat, nextExclusiveFloatEquidistant, nextExclusiveSignedDouble, nextExclusiveSignedFloat, nextExponential, nextFloat, nextFloat, nextGaussian, nextGaussian, nextGaussianFloat, nextGaussianFloat, nextInclusiveDouble, nextInclusiveDouble, nextInclusiveDouble, nextInclusiveFloat, nextInclusiveFloat, nextInclusiveFloat, nextInt, nextLong, nextLong, nextSign, nextSignedInt, nextSignedLong, nextTriangular, nextTriangular, nextTriangular, nextTriangular, nextUnsignedInt, previousInt, previousLong, probit, processSignedInt32, processUnsignedInt32, randomElement, randomElement, rateGamma, readExternal, seedFromMath, setState, setState, setState, setState, setState, setState, setState, setState, setState, setState, setState, setWith, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, skip, stringDeserialize, stringDeserialize, stringSerialize, stringSerialize, writeExternal

    Methods inherited from class Random

    doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface RandomGenerator

    equiDoubles, isDeprecated
  • Field Details

    • stateA

      protected int stateA
    • stateB

      protected int stateB
    • stateC

      protected int stateC
    • stateD

      protected int stateD
  • Constructor Details

    • XoshiroStarPhi32RNG

      public XoshiroStarPhi32RNG()
      Creates a new generator seeded using four calls to Math.random().
    • XoshiroStarPhi32RNG

      public XoshiroStarPhi32RNG(int seed)
      Constructs this XoshiroStarPhi32RNG by dispersing the bits of seed using setSeed(int) across the four parts of state this has.
      Parameters:
      seed - an int that won't be used exactly, but will affect all components of state
    • XoshiroStarPhi32RNG

      public XoshiroStarPhi32RNG(long seed)
      Constructs this XoshiroStarPhi32RNG by dispersing the bits of seed using setSeed(long) across the four parts of state this has.
      Parameters:
      seed - a long that will be split across all components of state
    • XoshiroStarPhi32RNG

      public XoshiroStarPhi32RNG(int stateA, int stateB, int stateC, int stateD)
      Constructs this XoshiroStarPhi32RNG by calling setState(int, int, int, int) on stateA and stateB as given; see that method for the specific details (the states are kept as-is unless they are all 0).
      Parameters:
      stateA - the number to use as the first part of the state; this will be 1 instead if both seeds are 0
      stateB - the number to use as the second part of the state
      stateC - the number to use as the third part of the state
      stateD - the number to use as the fourth part of the state
  • Method Details

    • getTag

      public String getTag()
      Specified by:
      getTag in class com.github.tommyettinger.random.EnhancedRandom
    • next

      public int next(int bits)
      Overrides:
      next in class com.github.tommyettinger.random.EnhancedRandom
    • nextInt

      public int nextInt()
      Can return any int, positive or negative, of any size permissible in a 32-bit signed integer.
      Specified by:
      nextInt in interface RandomGenerator
      Overrides:
      nextInt in class com.github.tommyettinger.random.EnhancedRandom
      Returns:
      any int, all 32 bits are random
    • nextLong

      public long nextLong()
      Specified by:
      nextLong in interface RandomGenerator
      Specified by:
      nextLong in class com.github.tommyettinger.random.EnhancedRandom
    • copy

      public XoshiroStarPhi32RNG copy()
      Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the copy, both will generate the same sequence of random numbers from the point copy() was called. This just needs to copy the state so it isn't shared, usually, and produce a new value with the same exact state.
      Specified by:
      copy in class com.github.tommyettinger.random.EnhancedRandom
      Returns:
      a copy of this RandomnessSource
    • setSeed

      public void setSeed(int seed)
      Sets the state of this generator using one int, running it through a GWT-compatible variant of SplitMix32 four times to get four ints of state, all guaranteed to be different.
      Parameters:
      seed - the int to use to produce this generator's states
    • setSeed

      public void setSeed(long seed)
      Sets the state of this generator using one long, running it through a GWT-compatible variant of SplitMix32 four times to get four ints of state, guaranteed to repeat a state no more than two times.
      Specified by:
      setSeed in class com.github.tommyettinger.random.EnhancedRandom
      Parameters:
      seed - the long to use to produce this generator's states
    • getStateA

      public int getStateA()
    • setStateA

      public void setStateA(int stateA)
      Sets the first part of the state to the given int. As a special case, if the parameter is 0 and this would set all states to be 0, this will set stateA to 1 instead. Usually, you should use setState(int, int, int, int) to set all four states at once, but the result will be the same if you set the four states individually.
      Parameters:
      stateA - any int
    • getStateB

      public int getStateB()
    • setStateB

      public void setStateB(int stateB)
      Sets the second part of the state to the given int. As a special case, if the parameter is 0 and this would set all states to be 0, this will set stateA to 1 in addition to setting stateB to 0. Usually, you should use setState(int, int, int, int) to set all four states at once, but the result will be the same if you set the four states individually.
      Parameters:
      stateB - any int
    • getStateC

      public int getStateC()
    • setStateC

      public void setStateC(int stateC)
      Sets the third part of the state to the given int. As a special case, if the parameter is 0 and this would set all states to be 0, this will set stateA to 1 in addition to setting stateC to 0. Usually, you should use setState(int, int, int, int) to set all four states at once, but the result will be the same if you set the four states individually.
      Parameters:
      stateC - any int
    • getStateD

      public int getStateD()
    • setStateD

      public void setStateD(int stateD)
      Sets the second part of the state to the given int. As a special case, if the parameter is 0 and this would set all states to be 0, this will set stateA to 1 in addition to setting stateD to 0. Usually, you should use setState(int, int, int, int) to set all four states at once, but the result will be the same if you set the four states individually.
      Parameters:
      stateD - any int
    • setState

      public void setState(int stateA, int stateB, int stateC, int stateD)
      Sets the current internal state of this XoshiroStarPhi32RNG with four ints, where each can be any int unless they are all 0 (which will be treated as if stateA is 1 and the rest are 0).
      Parameters:
      stateA - any int (if all parameters are both 0, this will be treated as 1)
      stateB - any int
      stateC - any int
      stateD - any int
    • getStateCount

      public int getStateCount()
      Overrides:
      getStateCount in class com.github.tommyettinger.random.EnhancedRandom
    • getSelectedState

      public long getSelectedState(int selection)
      Overrides:
      getSelectedState in class com.github.tommyettinger.random.EnhancedRandom
    • setSelectedState

      public void setSelectedState(int selection, long value)
      Overrides:
      setSelectedState in class com.github.tommyettinger.random.EnhancedRandom
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object