3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-02 01:18:40 +02:00

Factoids: sorting unnecessary for weighted selection

This commit is contained in:
Pragmatic Software 2020-06-17 02:24:46 -07:00
parent a2c918c94e
commit 13cb0f9dc6

View File

@ -599,8 +599,8 @@ sub select_weighted_item_from_list {
my $n = int rand $weight_sum;
for my $weight (sort { $a->[0] <=> $b->[0] } @weights) {
if ($n < $weight->[0]) {
for my $weight (@weights) {
if ($n <= $weight->[0]) {
return $list->[$weight->[1]];
}
$n -= $weight->[0];