Markov Chain Module


What does it do?

It creates messages from messages it ‘learns’ using a Markov Chain
Markov Chains are used by everyday electronics like Phones,
you know how phones can predict what you are about to write, that uses Markov Chains

Markov Chains create sentences using the data it has learned, Its not perfect but its used for procedurally generated sentences such as names for books, sample text inside of a book and such.

Sample Usage

local Markov = require(
local MarkovObject = Markov:New()
MarkovObject:Learn("Text you want to teach to the module goes here")
MarkovObject:Learn("Even more text goes here wow")
MarkovObject:Generate(MinAmountOfWords,MaxAmountOfWords,Seed) --Generates a message using the learned data

When adding a Seed it will continue the sentence for X many words.

The module might not always generate sensible text.
And make sure to filter anything that comes out of it if any players can see it.


--Creates new Markov Object (used for seperate datasets)

--MinLength is the mininmum amount of words generated in the sentence
--MaxLength is the max amount of words generated in the sentence
--Seed is used to manually start the sentence, using the seed "The" 
--would make it continue a sentence starting with "The ..."

MarkovObject:Learn(String) --Makes the Chain learn those words and how they interact

MarkovObject:MapWeb() --Used to "visualize" the Web of words and how they connect, currently
--it prints something like
        >Brown weightval
        >Yellow weightval
        >Human weighval 
weightval is the weight of the word (how likely it is that this word comes after "The" in this case)

Script File:
Markov.lua (2.4 KB)

Roblox Link:

Sample Place:


closed #2

This topic was automatically closed after 1 minute. New replies are no longer allowed.

opened #3


I really appreciate what you are doing for the community, but generally I would like to know more. I think it would be better if you put an explanation of what something is, instead of its actual name, unless it’s very popular so people wouldn’t be in doubt (I personally did not know what this was until I clicked your link and googled).

Also, are there any use cases for this? It sure seems cool, but currently I have no idea what it could be used for, maybe you could list a few examples?

Additionally put more content in your post instead of linking to an external page, so we don’t have to go any other links. You can of course link to the page, but type with your own words or at least paste some info about this, what it does.
You could say
What does this do? This module accepts various string inputs and then when calling :Generate() it will create a random phrase based on the inputs it has been given. This could be useful for X, and also Y where you do Z”.