@sapphire/utilities
Version:
Common JavaScript utilities for the Sapphire Community
21 lines (18 loc) • 679 B
JavaScript
;
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/lib/pickRandom.ts
function pickRandom(array, amount = 1) {
const arr = [...array];
if (typeof amount === "undefined" || amount === 1) {
return arr[Math.floor(Math.random() * arr.length)];
}
if (!arr.length || !amount) {
return [];
}
return Array.from({ length: Math.min(amount, arr.length) }, () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]);
}
__name(pickRandom, "pickRandom");
exports.pickRandom = pickRandom;
//# sourceMappingURL=pickRandom.cjs.map
//# sourceMappingURL=pickRandom.cjs.map