aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Markov.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin/Markov.pm')
-rw-r--r--Plugin/Markov.pm30
1 files changed, 18 insertions, 12 deletions
diff --git a/Plugin/Markov.pm b/Plugin/Markov.pm
index 1733372..e29bb45 100644
--- a/Plugin/Markov.pm
+++ b/Plugin/Markov.pm
@@ -74,18 +74,24 @@ sub some
sub do_markov
{
- my $word = $_[0];
- $word = some(keys %markov_data) unless $word;
- my $message = "";
- my $i = 0;
- do {
- $i++;
- $message .= "$word ";
- $word = some(@{$markov_data{$word}});
- } until(not $word or $word eq "" or $i == 1000);
-
- return if scalar(split / /, $message) <= 2;
- return $message;
+ my $tries = 0;
+
+ while ($tries++ < 10) {
+ my $word = $_[0];
+ $word = some(keys %markov_data) unless $word;
+ my $message = "";
+ my $i = 0;
+ do {
+ $i++;
+ $message .= "$word ";
+ $word = some(@{$markov_data{$word}});
+ } until(not $word or $word eq "" or $i == 1000);
+
+ return $message if scalar(split / /, $message) > 2;
+ }
+
+ # fallthrough: didn't form a long enough message in enough tries
+ return;
}
sub markov_cmd