Using a Markov chain to generate readable nonsense with 20 lines of Python
November 2023
Go to: Algorithm | Examples | Python implementation | Conclusion
I recently learned how to generate text using a simple Markov chain. The generated text is readable but is also complete nonsense; as prose it’s not worth much, but for predicting the next word like your phone keyboard’s suggestions, it’s surprisingly useful.
I learned about this algorithm in chapter 3 of Kernighan and Pike’s book The Practice of Programming, where they implement such a generator in various programmin...
Read more at benhoyt.com