3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-05-03 21:27:31 +02:00

Factoids: fix off-by-one in weighted selection

This commit is contained in:
Pragmatic Software 2020-06-17 11:36:42 -07:00
parent f2ab97e681
commit 6ea523f608

View File

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