UNPKG

math-toolbox

Version:

Lightweight and modular math toolbox

14 lines (12 loc) 427 B
/** * Generate a random float. * * @param {number} minValue - Minimum boundary. * @param {number} maxValue - Maximum boundary. * @param {number} [precision=2] - Precision. * @return {number} Generated float. */ function randomFloat (minValue, maxValue, precision = 2) { return parseFloat(Math.min(minValue + (Math.random() * (maxValue - minValue)), maxValue).toFixed(precision)) } export { randomFloat }