rendered paste body#!/usr/bin/perl
getVerb(/%probabilities);
getVerb(/%probabilities);
sub getVerb{
my %probabilities = shift(@_);
my $total = 0;
for my $verb ( keys %probabilities ) {
my $value = $probabilities{$verb};
print "\t\t\t$verb => $value\n";
$total += $value;
}
my $rand = rand(10000);
$rand /= 10000;
$rand *= $total;
$total = 0;
my $verbUsed;
my $tripped = 0;
for my $verb ( keys %probabilities ){
my $value = $probabilities{$verb};
if(($total + $value) < $rand){
$total += $value;
}else{
if(!$tripped){
$verbUsed = $verb;
$tripped =1;
}
}
}
return $verbUsed;
}