Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 9x 38x 36x 2x 34x 34x | import { isNumber } from '../assert/is-number';
/**
* Generate a random number >= min and <= max
*/
export function randomNumber(min = 0, max: number = Number.MAX_SAFE_INTEGER, fractionDigits?: number): number {
if (!isNumber(min) || !isNumber(max)) {
throw new Error('randomNumber must have min and max arguments');
}
const result = (Math.random() * (Math.abs(max - min))) + min;
return fractionDigits ? parseFloat(result.toFixed(fractionDigits)) : Math.round(result);
}
|