MRG is a template based random text generator.
Go to file

MRG is a template based text generator closely following the perchance grammar and borrowing features (or non-features) from similar generators such as rant, tracery, lorem ipsum, dada engine etc. MRG aims to be simple to use and easy to read. Extensibility is possible but shouldnt be at the expense of readability or simplicity. Extraneous syntax is kept to a minimum.

Generators are usually built around substitution from lists (such as this example from the perchance documentation).

  Your [pack] contains [item], [item] and [item].


  a few coins
  an old {silver|bronze} ring
  a handkerchief
  a shard of bone
  some lint
  a tin of tea leaves

This template generates sentences like “Your purse contains some lint, a few coins and a handkerchief.” or “Your knapsack contains a few coins, a shard of bones and an old silver ring.”

Writing templates

Templates are written in plain text with placeholders for text that can be replaced. They are usually based around lists of words or phrases. Special characters are limited to the square and curly brackets. i.e. “[ ]” and “{ }”. Some examples can be found in the data folder

The inclusion of a word in square brackets, like [word] will select something from the list called word. A list begins with a single word label and is followed by lines indented with 2 spaces.

Curly brackets can be used to indicate a choice, {this|that|the other} or a range of numbers {1-101} and can be used to generate the correct article or plural for a word using {a} or {s} (e.g. fish{s} generates “fishes” and ox{s} generates “oxen”)

There are a few modifier functions that can be used to filter the output such as [word.modifier] (e.g.. [mouse.plural] give “mice” or [mouse.upcase] gives “MOUSE”)

A template needs to include an output label with at least one item. An element is chosen randomly from the output list and used to generate a single output text.

  one word

The output items can select from a list like so…




The package can be installed via the racket package manager

racp pkg install moonrat

or installed manually from github

git clone

There an emacs mode for editing templates included (which can be installed via melpa)

M-x package install moonrat

and configured as required…

(use-package moonrat
  :init (setq moonrat-command "raco moonrat") ;; or “moonrat -v“
  :mode (("\\.mg\\'" . moonrat-mode))
  :bind (:map moonrat-mode-map
              ("C-c g" . moonrat-generate)))


Save a template in a file and run moonrat to generate text on the command line…

raco moonrat data/

further details…

raco moonrat -h

or from a racket programme

#lang racket
(require moonrat)
(load-generator-file "")

Moon Grade Ranter

Darius Kazemi has compiled a collection of copora for “the creation of weird internet stuff” specifically for text generation. MRG includes a basic conversion utility to help use the corpora lists with moonrat. The converted lists are not validated in any way and will almost certainly need some manual coercion to be useful.

copora can be converted from a given url or file…

raco cp2mg -u
raco cp2mg -f data/corpora/interjections.json -o data/

Weird Machinery

The templates are almost certainly a weird machine capable of unexpected machinations using list substitution (well formed recursive lists) and choice (even without assignment). Implementation is left as an exercise for the reader (see also string rewriting and antigram)

Syntax, grammar and reference

  • output

  • a word

  • a [word]

  • {word|another word}

  • {a} thing

  • some thing{s}

  • a [word.plural]

  • [the four word title.title-case]

  • a [nested.list.word]

  • // comments are on a line by themselves (not yet inline)

    (to be continued…)

links & further

Included, precluded, transcluded and occluded…

nik gaffney 44fbf0c8c5 static sputtering 2023-09-22 18:33:58 +02:00
.github/workflows intense discordant music 2022-09-25 18:32:48 +02:00
data seedling 2022-09-25 18:23:15 +02:00
img static sputtering continues 2022-09-26 11:03:57 +02:00
scribblings seedling 2022-09-25 18:23:15 +02:00
src engine revving 2022-10-16 14:09:28 +02:00
.gitignore engine revving 2022-10-16 14:09:28 +02:00
LICENSE seedling 2022-09-25 18:23:15 +02:00 static sputtering continues 2022-09-26 11:03:57 +02:00
info.rkt static sputtering 2023-09-22 18:33:58 +02:00
main.rkt seedling 2022-09-25 18:23:15 +02:00