my @x = @_; my $y = 0; my $i = 0; until ($i > $#x) { $y = $y + $x[$i]; $i = $i + 1; } $x[0] = $x[0] / $y; $i = 1; until ($i > $#x) { $x[$i] = $x[$i - 1] + $x[$i] / $y; $i = $i + 1; } $y = rand(); # This bit constitutes the "function" $i = 0; until ($y < $x[$i]) { $i = $i + 1; } return $i;
In reply to Re: Weighted random numbers generator
by Anonymous Monk
in thread Weighted random numbers generator
by spurperl
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |