mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-25 04:02:37 +01:00
Factoids: weights can now be fractional
This commit is contained in:
parent
24496ef790
commit
5495a6b406
@ -586,7 +586,7 @@ sub select_weighted_item_from_list {
|
|||||||
|
|
||||||
for (my $i = 0; $i <= $#$list; $i++) {
|
for (my $i = 0; $i <= $#$list; $i++) {
|
||||||
my $weight = 1;
|
my $weight = 1;
|
||||||
if ($list->[$i] =~ s/:weight\((\d+)\)//) {
|
if ($list->[$i] =~ s/:weight\(([0-9.-]+)\)//) {
|
||||||
$weight = $1;
|
$weight = $1;
|
||||||
}
|
}
|
||||||
$weights[$i] = [ $weight, $i ];
|
$weights[$i] = [ $weight, $i ];
|
||||||
@ -597,7 +597,7 @@ sub select_weighted_item_from_list {
|
|||||||
return $list->[$index];
|
return $list->[$index];
|
||||||
}
|
}
|
||||||
|
|
||||||
my $n = int rand $weight_sum;
|
my $n = rand $weight_sum;
|
||||||
|
|
||||||
for my $weight (@weights) {
|
for my $weight (@weights) {
|
||||||
if ($n < $weight->[0]) {
|
if ($n < $weight->[0]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user