How to choose a weighted random array element in Javascript?
Both answers above rely on methods that will get slow quickly, especially the accepted one. This is a function which just takes two same-length lists, items and weights, and returns a random item from items according to their corresponding likelihoods of being chosen in weights. The weights array should be of nonnegative numbers, but it … Read more