<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc" -->

---
title: AI or ain't: Markov Chains | daily.dev
description: A hands-on walkthrough of Markov chains as a simple text-generation technique, contrasting them with rule-based chatbots like Eliza. Covers the history of Mark...
canonical: https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: AI or ain't: Markov Chains | daily.dev
og:description: A hands-on walkthrough of Markov chains as a simple text-generation technique, contrasting them with rule-based chatbots like Eliza. Covers the history of Mark...
og:url: https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc
og:image: https://api.daily.dev/og/posts/NtfrGNKyC.png
og:image:alt: AI or ain't: Markov Chains
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# AI or ain't: Markov Chains

**[zserge's blog](https://daily.dev/sources/zserge)** · 9 min read · 0 upvotes · 0 comments

## Summary

A hands-on walkthrough of Markov chains as a simple text-generation technique, contrasting them with rule-based chatbots like Eliza. Covers the history of Mark V. Shaney, a late-1980s Markov chain bot, then builds a ~30-line Go implementation that trains on text and generates sentences. Demonstrates how increasing the prefix length (n-gram order) from 1 to 3 improves coherence, using Simpsons quotes and Paul Graham essays as training corpora. Closes by framing Markov chains as a basic form of machine learning and teases a follow-up on neural networks.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://zserge.com/posts/ai-markov>

## Questions this post answers

### How do I build a simple Markov chain text generator in Go?

A basic Markov chain generator can be built in around 30 lines of Go: read training text line by line, split into words, and store a map from each word (or n-word prefix) to a list of words that followed it. To generate text, pick a random starting word, then repeatedly look up candidate next words for the current word or prefix and pick one at random until no candidates remain.

_Developers experimenting with text generation techniques can find implementation walkthroughs like this on daily.dev._

### Why does increasing the prefix length in a Markov chain improve generated text quality?

Using two or three words as the prefix instead of one makes generated text noticeably more coherent, because each transition is conditioned on more context rather than just the previous single word. For English text, a prefix length of 2 is considered a good balance, since higher lengths like 3 start to just repeat exact phrases from the training corpus rather than producing novel combinations.

_Anyone tuning text-generation parameters can compare tradeoffs like this one via daily.dev._

### What was Mark V. Shaney and how did it generate text?

Mark V. Shaney was a bot created by Rob Pike and others that posted messages to Usenet newsgroups in the late 1980s, generated using a Markov chain trained on the Tao Te Ching. It produced grammatically plausible but semantically nonsensical English sentences by chaining together word transitions based on probabilities learned from the source text.

_Readers tracing the history of text-generation techniques can dig into stories like this on daily.dev._

## Similar posts on daily.dev

- [Medium](https://daily.dev/posts/medium-mocmywq0j) · Medium · 0 upvotes · 0 comments
- [I Fed 24 Years of My Blog Posts to a Markov Model](https://daily.dev/posts/i-fed-24-years-of-my-blog-posts-to-a-markov-model-3dastemhp) · Hacker News · 1 upvotes · 0 comments
- [AI Coding Assistant Strategy Slashes Token Bills](https://daily.dev/posts/ai-coding-assistant-strategy-slashes-token-bills-hcwp3e0fl) · IEEE Spectrum · 0 upvotes · 0 comments
- [1. From Answer to Outcome](https://daily.dev/posts/1-from-answer-to-outcome-oprmxy0yl) · Planet Python · 0 upvotes · 0 comments

---

Tags: [#machine-learning](https://daily.dev/tags/machine-learning), [#golang](https://daily.dev/tags/golang), [#nlp](https://daily.dev/tags/nlp), [#algorithms](https://daily.dev/tags/algorithms)

[View this post on daily.dev](https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"AI or ain't: Markov Chains","url":"https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc"},"datePublished":"2026-08-23T10:20:14.598Z","dateModified":"2026-08-23T10:21:14.305Z","description":"A hands-on walkthrough of Markov chains as a simple text-generation technique, contrasting them with rule-based chatbots like Eliza. Covers the history of Mark...","image":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","thumbnailUrl":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","isAccessibleForFree":true,"articleSection":"zserge's blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"zserge's blog","logo":"https://media.daily.dev/image/upload/s--KQnFBOIT--/f_auto,q_auto/v1787480407/logos/zserge","url":"https://daily.dev/sources/zserge"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"machine-learning,golang,nlp,algorithms","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"zserge's blog","item":"https://daily.dev/sources/zserge"},{"@type":"ListItem","position":3,"name":"AI or ain't: Markov Chains"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/ai-or-ain-t-markov-chains-ntfrgnkyc#faq","mainEntity":[{"@type":"Question","name":"How do I build a simple Markov chain text generator in Go?","acceptedAnswer":{"@type":"Answer","text":"A basic Markov chain generator can be built in around 30 lines of Go: read training text line by line, split into words, and store a map from each word (or n-word prefix) to a list of words that followed it. To generate text, pick a random starting word, then repeatedly look up candidate next words for the current word or prefix and pick one at random until no candidates remain. Developers experimenting with text generation techniques can find implementation walkthroughs like this on daily.dev."}},{"@type":"Question","name":"Why does increasing the prefix length in a Markov chain improve generated text quality?","acceptedAnswer":{"@type":"Answer","text":"Using two or three words as the prefix instead of one makes generated text noticeably more coherent, because each transition is conditioned on more context rather than just the previous single word. For English text, a prefix length of 2 is considered a good balance, since higher lengths like 3 start to just repeat exact phrases from the training corpus rather than producing novel combinations. Anyone tuning text-generation parameters can compare tradeoffs like this one via daily.dev."}},{"@type":"Question","name":"What was Mark V. Shaney and how did it generate text?","acceptedAnswer":{"@type":"Answer","text":"Mark V. Shaney was a bot created by Rob Pike and others that posted messages to Usenet newsgroups in the late 1980s, generated using a Markov chain trained on the Tao Te Ching. It produced grammatically plausible but semantically nonsensical English sentences by chaining together word transitions based on probabilities learned from the source text. Readers tracing the history of text-generation techniques can dig into stories like this on daily.dev."}}]}
```

