Sampling from a frequency distribution I have a dataset representing a frequency distribution:
|item|frequency|
|-|-|
|a|1|
|b|1|
|c|1|
|d|1|
|e|2|
|f|2|
|g|10|
h,143
j,724
The data is fairly exponential in character, with a few items occurring frequently, then a long tail of single occurrences.  The dataset is >>1 million lines/items is size.  What is the best way to take a random sample from the distribution?  This would be python code not R.

One way you could this is divide your data to groups with equal frequency, then first randomly choose a group such that the probability of choosing a group will be equal to the group frequency (you can do this e.g. by generating a uniform random number $x$ between 0 and 1, and selecting group $i$ if $a_i < x < b_i$ such that $p_i = b_i - a_i$)
Then just randomly select one of elements of the group.
