UNPKG

lazzy.ts

Version:

Fast and lightweight library for lazy operations with iterable objects.

27 lines 743 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.random = void 0; const rangeDefaults = { min: 0, max: Number.MAX_SAFE_INTEGER - 1, precision: 0 }; function* random(parameters) { let { min, max, precision } = Object.assign(Object.assign({}, rangeDefaults), parameters); const tempMax = max; max = Math.max(min, max); min = Math.min(min, tempMax); if (precision < 0) { precision = 0; } else if (precision > 16) { precision = 16; } const p = Math.pow(10, precision); const diff = max - min; while (true) { yield Math.trunc((Math.random() * diff + min) * p) / p; } } exports.random = random; //# sourceMappingURL=random.js.map