/** * Makes a CriticalRNG with a luck factor of 0 and a DiverRNG with the given seed for its RandomnessSource. * @param seed any long */ public CriticalRNG(long seed) { super(new DiverRNG(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. */ public StatefulRNG(long seed) { this(new DiverRNG(seed)); } /**
/** * Default constructor; uses {@link DiverRNG}, which is of high quality, but low period (which rarely matters * for games), and has excellent speed, tiny state size, and natively generates 64-bit numbers. The seed can be * any long, including 0. * @param seed any long */ public RNG(long seed) { this(new DiverRNG(seed)); }
/** * 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 need to * copy the state so it isn't shared, usually, and produce a new value with the same exact state. * * @return a copy of this RandomnessSource */ @Override public DiverRNG copy() { return new DiverRNG(state); }
/** * Uses the provided source of randomness for all calculations. This constructor should be used if an alternate * RandomnessSource other than DiverRNG is desirable, such as to keep compatibility with earlier SquidLib * versions that defaulted to MersenneTwister, LightRNG, ThrustAltRNG, or LinnormRNG. * <br> * If the parameter is null, this is equivalent to using {@link #RNG()} as the constructor. * @param random the source of pseudo-randomness, such as a LightRNG or LongPeriodRNG object */ public RNG(RandomnessSource random) { this.random = (random == null) ? new DiverRNG() : random; }
/** * Makes a CriticalRNG with a luck factor of 0 and a randomly-seeded DiverRNG for its RandomnessSource. */ public CriticalRNG() { super(new DiverRNG()); }
/** * Makes a CriticalRNG with the given luck factor and a randomly-seeded DiverRNG for its RandomnessSource. * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns */ public CriticalRNG(float luck) { super(new DiverRNG()); this.luck = luck; }
/** * Makes a CriticalRNG with the given luck factor and a DiverRNG with the given seed for its RandomnessSource. * @param seed any long * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns */ public CriticalRNG(long seed, float luck) { super(new DiverRNG(seed)); this.luck = luck; }
/** * Default constructor; uses {@link DiverRNG}, which is of high quality, but low period (which rarely matters * for games), and has excellent speed, tiny state size, and natively generates 64-bit numbers. * <br> * Previous versions of SquidLib used different implementations, including {@link LightRNG}, {@link ThrustAltRNG}, * {@link LinnormRNG}, and {@link MersenneTwister}. You can still use one of these by instantiating one of those * classes and passing it to {@link #RNG(RandomnessSource)}, which may be the best way to ensure the same results * across versions. */ public RNG() { this(new DiverRNG()); }
/** * Creates a new random number generator. This constructor uses * a DiverRNG with a random seed. */ public CustomRandom() { randomnessSource = new DiverRNG(); }
/** * Makes a CriticalRNG with a luck factor of 0 and a DiverRNG with the given seed for its RandomnessSource (this * will hash seedString using {@link CrossHash#hash64(CharSequence)} and use the result to seed the DiverRNG). * @param seedString any String */ public CriticalRNG(CharSequence seedString) { super(new DiverRNG(CrossHash.hash64(seedString))); }
/** * Makes a CriticalRNG with a luck factor of 0 and a DiverRNG with the given seed for its RandomnessSource (this * will hash seedString using {@link CrossHash#hash64(CharSequence)} and use the result to seed the DiverRNG). * @param seedString any String * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns */ public CriticalRNG(CharSequence seedString, float luck) { super(new DiverRNG(CrossHash.hash64(seedString))); this.luck = luck; }
/** * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode, * instead using {@link CrossHash#hash64(CharSequence)}) as a seed for {@link DiverRNG}, which is of high quality, * but low period (which rarely matters for games), and has excellent speed, tiny state size, and natively generates * 64-bit numbers. */ public RNG(CharSequence seedString) { this(new DiverRNG(CrossHash.hash64(seedString))); }
public StatefulRNG(RandomnessSource random) { super((random instanceof StatefulRandomness) ? random : new DiverRNG(random.nextLong())); }
/** * 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 * {@code new StatefulRNG(text)} with {@code 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. */ public StatefulRNG(CharSequence seedString) { this(new DiverRNG(CrossHash.hash64(seedString))); }
@Override public StatefulRandomness restore(String text) { long state = StringKit.longFromHex(text); try { StatefulRandomness sr = (StatefulRandomness) ClassReflection.newInstance(ClassReflection.forName(text.substring(text.indexOf(':') + 1))); sr.setState(state); return sr; }catch (Exception re) { return new DiverRNG(state); } } };
DiverRNG random = new DiverRNG(seed); int w = (width << 1) + 2, h = (height << 1) + 2; GreasedRegion[] regions = new GreasedRegion[]{