Prerequisites: arr.length === times.length and each times[i] >= 1.
Beware that this function takes ownership of arr and times references.
times and arr array values get randomly shuffled, moreover
times[i] gets decreased each time arr[i] value was picked.
Thus you should copy arr and times array if those changes are unacceptable,
e.g. pickRandomItems([...arr], [...times])
Type parameters
T
Parameters
arr: T[]
Array to pick values from
times: number[]
Array of numbers of times a value can be picked from arr
Returns a random item from the given array. If array.length is 0 or subarrayRange goes beyond array index limits, may return
undefined
.