Randomly choosing from a list with weighted probabilities
The idea: Iterate through all the elements and set the value of each element as the cumulative frequency thus far. Generate a random number between 1 and the sum of all frequencies Do a binary search on the values for this number (finding the first value greater than or equal to the number). Example: Element … Read more