Gibrish generates fake words from real words.
Gibrish is on npm:
npm install gibrish
var Gibrish = require("gibrish"); var g = new Gibrish(); var massachusettsTowns = ["Abington", "Acton", /* etc. */ ]; g.push(massachusettsTowns); g.generate(); "Brainfield" g.generate(); "Pittleborough" g.generate(); "East Barnster" g.generate(); "Brewster-by-the-Sea"
Constructs a new gibrish instance. This constructor is the only export of the module:
var Gibrish = require("gibrish")
[options](Object) - Options for the instance (not required).
[options.order=3](Number) - The order of the Markov chain. The order is the number of previous characters used to determine the next. Defaults to
[options.novel=true](Boolean) - Exclusively generate words that do not exist in the training set. Defaults to
[options.maxTries=10](Number) - Number of times
generate()will retry if its output is not novel. Defaults to
Object: Returns an Gibrish instance.
Add training words to the instance. These words are processed and added to the instance's database for use in
words(Array of Strings or String) - words to add to the instance. If an Array of Strings is given, each member will be added as a word. If a String is given it will be added as a single word.
undefined: Does not return a value.
Generates a word from instance's database. This method is not deterministic, as Gibrish uses a random probabilistic algorithm.
generate() will return
novel is truthy and
generate() has not found a novel word in
maxTries. This may happen often if
order is relatively high compared to the training words' average length or if few training words have been added.
[options](Object) - Options for generation (not required). These options are identical to those in the
Gibrishconstructor except that
orderis ignored (an instance's order is immutable). Any
generate()options override those in the constructor.
String or null: Returns a generated word or
null if one could not be created.
Gibrish creates a Markov chain from input words and uses it to generate gibberish words. Markov chains are made up of states and links between those states. In Gibrish's case, the states are just letters and other characters you'd find in words (like spaces and dashes). A word is built by linking states together. The links are chosen randomly, according to the distribution of links in the training words.
A chain's order (or memory) is the number of states it uses to determine its next state. In Gibrish the default order is 3.
Don't worry; it's really not that scary. For example, here's how the beginning of the gibberish town name "East Barnster" is created from actual Massachusetts town names:
Creating gibberish words is mainly just for fun. One practical use, however, is to create memorable but non-dictionary passwords (especially useful if a system limits your password length). Gibberish words are a nice compromise between real words (easy to type and easy to remember) and random characters (not found in dictionaries and therefore more secure).