I'd like to pick up a item according to its given probability from a hashtable. For example, I am storing string "apple" "banana" and "pineapple" into my hashtable. Now I'd like to get a item out of the hashtable according to their given probability, saying the probability to get "apple" is 30%, a "banana" is 30% and a "pineapple" is 40%. Could anyone help me with this?
The reason I need to use a Hashtable is that I am actually dealing a large amount of strings which are the words in a certain book. The probability of the word is depended on its occurrence in the book. For example, if there are 100,000 words in a certain book and the word "dog" occurs 1,000 times. The probability for me to get a "dog" when I am calling from my function should be 1,000/100,000.