UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

16 lines (13 loc) 527 B
/** * Returns a random number within a normal distribution (Bell/Gaussian curve) * @param {number} [quality=6] controls number of "die rolls" used to approximate curve, more rolls - better approximation but higher cost of computation * @param {function():number} random * @returns {number} value between 0 and 1 with normal weight at 0.5 */ export function randomGaussian(random, quality = 6) { let s = 0; for (let i = 0; i < quality; i++) { s += random(); } return s / quality; }