loop through the lines parse out the key and the frequency save the key and frequency as a two-element array inside an array keep a running total of the frequencies set an accumulator to 0 loop through the array replace each frequency value with a value representing the frequency plus the accumulator, divided by the total of the frequencies add the original frequency to the accumulator get a random positive number less than 1 loop through the array one more time if the random number is less than the relative frequency value we've found our key, print it and exit the loop