svcorelib
Version:
Core library used in the projects of Sv443 and the Sv443 Network. Contains tons of miscellaneous QoL features.
17 lines (11 loc) • 368 B
JavaScript
const randRange = require("./randRange");
function randomItemIndex(array)
{
if(!Array.isArray(array))
throw new Error("Parameter is not an array");
if(array.length === 0)
return [undefined, undefined];
const idx = randRange(0, array.length - 1);
return [array.at(idx), idx];
}
module.exports = randomItemIndex;