You have an array of positive integers representing weights. You need to pick an index randomly where the probability of picking index is proportional to its weight.
For example, if weights are , then index has probability , index has probability , and index has probability .
How can you implement this so each call runs fast, even if weights array is large?