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:
parent
f2ab97e681
commit
6ea523f608
@ -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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user