Roquen's Random Number Generators...

As found here:

@Roquen of these parts (haven’t seen 'em for a while…) has some decent implementations of pseudo random number generators. In particular I’ve lately switched from LCR64 to XorShift64 in my terrain generation as it gives veeeery slightly more pleasing results… provided you’ve got a lot of bits set in your seed. It turns out that using the map index as a seed (essentially an integer sequence starting at zero) gives a very poor initial random number from XorShift64 - it takes quite a few reads to get a decent number of bits to start twiddling, and you can end up with a very not-at-all-random looking sequence of numbers for quite some time.

To fix this I’ve updated my setSeed() function to make a Wang hash of the incoming seed, which means inadvertently using a sequence of small integers with few bits in won’t result in terribly obvious artefacts when reading the initial series of numbers.

Here’s a Wang hash, with a handy link to the source of this implementation:


	/**
	 * Wang hash. See <a href="http://www.burtleburtle.net/bob/hash/integer.html">here</a> for details.
	 * @param value
	 * @return a hash of the value
	 */
	public static int wang_hash(int value) {
		value = (value ^ 61) ^ (value >>> 16);
		value *= 9;
		value = value ^ (value >>> 4);
		value *= 0x27d4eb2d;
		value = value ^ (value >>> 15);
		return value;
	}

Cas :slight_smile: