String generator

ROT.StringGenerator is an implementation of a high order Markov process. This machine learning technique needs to be trained first (with a set of typical strings); after training, it generates strings similar to those used as a training set.

Read more about the implementation (Dirichlet prior, simplified Katz back-off) in this RogueBasin article. The constructor accepts an optional configuration object with the following keys:

There are only two important public methods: observe() for training and generate() for producing results. In the following example, we will use all standard Java 7 class names as a training set; let's see what new Java stuff our generator produces.

var sg = new ROT.StringGenerator(); var r = new XMLHttpRequest(); r.open("get", "java.txt", true); r.send(); r.onreadystatechange = function() { if (r.readyState != 4) { return; } var lines = r.responseText.split("\n"); while (lines.length) { var line = lines.pop().trim(); if (!line) { continue; } sg.observe(line); } for (var i=0; i<20; i++) { SHOW(sg.generate()); } }