mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Factoids: sorting unnecessary for weighted selection
This commit is contained in:
parent
a2c918c94e
commit
13cb0f9dc6
@ -599,8 +599,8 @@ sub select_weighted_item_from_list {
|
|||||||
|
|
||||||
my $n = int rand $weight_sum;
|
my $n = int rand $weight_sum;
|
||||||
|
|
||||||
for my $weight (sort { $a->[0] <=> $b->[0] } @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…
Reference in New Issue
Block a user