UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

19 lines (15 loc) 437 B
/** * Performs a probabilistic rounding where a fraction is rounded up or down with probability equal to the fraction * @param {number} number * @param {function} random * @returns {int} */ export function roundFair(number, random) { const mantissa = number % 1; const roll = random(); if (roll > mantissa) { return Math.floor(number); } else { return Math.ceil(number); } }