everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
24 lines (23 loc) • 865 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomUniqueRange = void 0;
/**
* Returns an array of random unique integers within the range [min, max].
* @author @dailker
* @param {number} count - The number of unique random numbers to generate.
* @param {number} min - The minimum value (inclusive).
* @param {number} max - The maximum value (inclusive).
* @returns {number[]} An array of unique random numbers.
*/
function randomUniqueRange(count, min, max) {
const pool = [];
for (let i = min; i <= max; i++)
pool.push(i);
const result = [];
while (result.length < count && pool.length) {
const idx = Math.floor(Math.random() * pool.length);
result.push(pool.splice(idx, 1)[0]);
}
return result;
}
exports.randomUniqueRange = randomUniqueRange;