diff --git a/modules/markov.go b/modules/markov.go index 7b0d539..cfb4b96 100644 --- a/modules/markov.go +++ b/modules/markov.go @@ -222,7 +222,11 @@ func (c *MarkovChain) Generate(n int, in string) string { for attempt := 0; attempt < 10; attempt++ { p = make(MarkovPrefix, c.prefixLen) inWords := strings.Split(in, " ") - start = inWords[rand.Intn(len(inWords))] + if attempt < 9 { + start = inWords[rand.Intn(len(inWords))] + } else { + start = "" + } p.Shift(start) xlog.Debug("Looking for answer on [%s]", start) for i := 0; i < n; i++ { @@ -242,13 +246,7 @@ func (c *MarkovChain) Generate(n int, in string) string { } } start = strings.Trim(start, " ") - if len(words) == 0 { - xlog.Debug("No answer found") - return start + " ... pfrrrz" - } else { - xlog.Debug("Found words: [%s]", strings.Join(words, " ")) - return start + " " + strings.Join(words, " ") - } + return start + " " + strings.Join(words, " ") } // Save the chain to a file