/** * @class (Markov process)-based string generator. * Copied from a RogueBasin article. * Offers configurable order and prior. * @param {object} [options] * @param {bool} [options.words=false] Use word mode? * @param {int} [options.order=3] * @param {float} [options.prior=0.001] */ ROT.StringGenerator = function(options) { this._options = { words: false, order: 3, prior: 0.001 } for (var p in options) { this._options[p] = options[p]; } this._boundary = String.fromCharCode(0); this._suffix = this._boundary; this._prefix = []; for (var i=0;i this._options.order) { context = context.slice(-this._options.order); } else if (context.length < this._options.order) { context = this._prefix.slice(0, this._options.order - context.length).concat(context); } while (!(this._join(context) in this._data) && context.length > 0) { context = context.slice(1); } return context; } ROT.StringGenerator.prototype._pickRandom = function(data) { var total = 0; for (var id in data) { total += data[id]; } var random = ROT.RNG.getUniform()*total; var part = 0; for (var id in data) { part += data[id]; if (random < part) { return id; } } }