Main Categories: | Landscape | Fenceposts | Wildlife | Trees | Mushrooms | Art | Games || All Posts ||
for daily images, visit my ||Tumblr||

Friday, 29 August 2014

Markov Text Generator

I wrote this simple Markov text generator last week - mostly as an exercise in getting to know the Dart programming language and tools.

The generator works by being presented with a body of text, and it goes through the text, recording statistically what letters tend to follow on from the various sequences of letters. Then it uses this data to generate more text using the same statistical probabilities for each letter sequence. See this wikipedia link for more details.

For such an inanely simple algorithm, it is capable of coming up with beguilingly complex results:

Seeded with a 234k chunk of The Lord of the Rings.

I'm scheming on how I might use it in computer games... NPC background chatter might be one use, or libraries full of books - you could insert useful text on a particular page, and have the players get a clue about what to look up in the book to get useful results, rather than just inane babble!

But text is only a sideline - Markov Chains might also be useful in ai routines, random level generators - anywhere where you want to approximate a complex system without modelling all the underlying processes.

No comments: