JSFiddle - React, Tailwind, and code Playground
JavaScript
(function($) {
$.rand = function(arg) {
if ($.isArray(arg)) {
return arg[$.rand(arg.length)];
} else if (typeof arg == "number") {
return Math.floor(Math.random() * arg);
} else {
return 4; // chosen by fair dice roll
}
};
})(jQuery);
var items = [523,3452,334,31,57,5346];
console.log($.rand(10));
console.log($.rand(items));
console.log($.rand());