Weighted random numbers

There is a straightforward algorithm for picking an item at random, where items have individual weights: 1) calculate the sum of all the weights 2) pick a random number that is 0 or greater and is less than the sum of the weights 3) go through the items one at a time, subtracting their weight … Read more