i have a chatbot that does this
you basically have a huge network of single-word values connected and logged by arrays (i stored it in a scriptobject)
word[0] = word
wordChain[word, 0] = wordc
wordChain[word, 1] = wordc
wordChains[word] = 1
words = 0
and so on, and then to get a string, you'd just start at a random word (word[getRandom(0, words)]) and then continue tagging on random strung words (wordChain[lastword, getRandom(0, wordChains[lastword])])