use strict; # five options, with 50%, 25%, 10%, 10% and 5% # chances respectively. my %hash = ( option1 => 50, option2 => 25, option3 => 10, option4 => 10, option5 => 5); # get rand num - may want to seed it first though :) my $rnd_num = int(rand(100)); my ($total,$key); # cycle through hash values for (keys %hash) { # keep running total $total += $hash{$_}; # keep going until rand num exceeded next unless ($total >= $rnd_num); # then set this as value selected and stop loopin $key = $_; last; } # randomly selected key is... print "$key selected\n"; #### my $value_sum = eval join '+', values %hash; my $rnd_num = int(rand($value_sum ));