📒 A library for building Markov chains from text
C#
Example: build & generate
varmc=new MarkovChain(3);// k = degree
mc.Add("a");
mc.Add("as");
mc.Add("asd");
mc.Add("asd1");
mc.Add("asd12");
mc.Add("asd123");// compute distribution:// required before calling `Generate`
mc.Prepare();varr=new Random(3);// generate value
mc.Generate(r)// generate value in string buildervarsb=new StringBuilder();
mc.Generate(r, sb);// save to disk
mc.WriteToFile(...);
Example: load from file
varmc=new MarkovChain();// note: parameterless constructor// load from disk
mc.ReadFromFile(...);// no need to call `Prepare`// generate value
mc.Generate(r)// generate value in string buildervarsb=new StringBuilder();
mc.Generate(r, sb);