UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

22 lines (19 loc) 689 B
const BIT_NOISE1 = 0xB5297A4D; const BIT_NOISE2 = 0x68E31DA4; const BIT_NOISE3 = 0x1B56C4E9; /** * Based on Squirrel3 hash function by Squirrel Eiserloh * Alex: Personally I found it to have low entropy, so I don't see it as very useful * @see GDC 2017 presentation on "Math for Game Programmers: Noise-Based RNG" * @param {number} value expected to be an integer, if not - it will be truncated to such * @returns {number} signed 32-bit integer */ export function squirrel3(value) { let hash = value * BIT_NOISE1; hash ^= (hash >> 8); hash += BIT_NOISE2; hash ^= (hash << 8); hash *= BIT_NOISE3; hash ^= (hash >> 8); return hash; }