my $pick; my $weight; while (my ($p, $w) = each %$group) { $weight += $w; $pick = $p if rand ($weight) < $w; } # # $pick now contains a weighted choice. #
In reply to Re: Weighted random selection
by JavaFan
in thread Weighted random selection
by cosmicperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |