@studiometa/js-toolkit
Version:
A set of useful little bits of JavaScript to boost your project! 🚀
16 lines (15 loc) • 437 B
JavaScript
import { isArray, isString } from "./is.js";
function randomInt(a, b = 0) {
return Math.floor(Math.random() * (a - b + 1)) + b;
}
function randomItem(items) {
if (!isArray(items) && !isString(items)) {
throw new Error("randomItem() expects an array or a string as argument.");
}
return items.length > 0 ? items[randomInt(items.length - 1)] : void 0;
}
export {
randomInt,
randomItem
};
//# sourceMappingURL=random.js.map