I have a large text and I need to select words randomly in proportion to their frequencies.
A raw method is to put all the words in an array (N indexes) and to use a random (uniform) generator to generate numbers between 0 to N.
For example, a word $w_1$ occurs 5000 times in the text and the word $w_3$ occurs 100 times. $w_1$ should be selected with a probability that is 50 times larger than the probability for $w_3$.
This "raw" method does not seem to be effective (or feasible) if a I have a large text. Is there a better way to select the items randomly and in proportion to their frequencies?