All pastes #992863 Raw Edit

Stuff

public text v1 · immutable
#992863 ·published 2008-04-22 05:15 UTC
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;
}