Class StatefulRNG

java.lang.Object
squidpony.squidmath.RNG
squidpony.squidmath.StatefulRNG
All Implemented Interfaces:
Serializable, IRNG, IStatefulRNG, RandomnessSource, StatefulRandomness
Direct Known Subclasses:
DeckRNG, EditRNG

public class StatefulRNG
extends RNG
implements Serializable, IStatefulRNG
A slight variant on RNG that always uses a stateful RandomessSource and so can have its state set or retrieved using setState() or getState(). Created by Tommy Ettinger on 9/15/2015.
Author:
Tommy Ettinger
See Also:
Serialized Form
  • Constructor Details

    • StatefulRNG

      public StatefulRNG()
    • StatefulRNG

      public StatefulRNG​(RandomnessSource random)
    • StatefulRNG

      public StatefulRNG​(long seed)
      Seeded constructor uses DiverRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size.
    • StatefulRNG

      public StatefulRNG​(CharSequence seedString)
      String-seeded constructor uses the hash of the String as a seed for DiverRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size. Note: This constructor changed behavior on April 22, 2017, again on December 23, 2017, and again on June 14, 2018. The first was when it was noticed that it was not seeding very effectively (only assigning to 32 bits of seed instead of all 64). The older behavior isn't fully preserved, since it used a rather low-quality String hashing algorithm and so probably had problems producing good starting seeds, but you can get close by replacing new StatefulRNG(text) with new StatefulRNG(new LightRNG(CrossHash.hash(text))). The new technique assigns to all 64 bits and has less correlation between similar inputs causing similar starting states. It's also faster, but that shouldn't matter in a constructor. It uses a better hashing algorithm because CrossHash no longer has the older, worse one. The latest change in June switched to DiverRNG instead of LightRNG.
  • Method Details