Have you ever had to pick a random value from an array or a range of numbers and wished there was a simple one-liner way of doing it? Me too! The following function will get that done for you:
This function will accept zero, one or two arguments:
minOrArray
{number | Array} - If a number is given and this is the only argument specified this will be used as thelimit
value while0
will be used as the inclusive boundary for the range of numbers that can be returned. If a number is given andlimit
is notundefined
ornull
this will be the the inclusive boundary for the range of numbers that can be returned. If an array is given a random value from this array will be returned.limit
{number | undefined | null} - If a number is given it will represent the exclusive boundary of the range of numbers from which a random number can be chosen.