in reply to Biased random number selection

This is the algorithm I've seen posted elsewhere (when I did a search a long time ago in the perl newsgroups), and that I've used myself:
my($tw, $winner) = (0, undef); my @numbers = ( ... ); my @freq = ( ... ); for my $idx (0..$#numbers) { $tw += $freq[ $idx ]; $winner = $idx if rand($tw) < $freq[ $idx ]; } return $winner;
There's also an example in the Perl Cookbook, apparently, if you have that.