Abulafia, if you are not already familiar with it, is a Wikipedia-like site for automating random tables. It allows you to create tools like this page, which is an automation of Patrick’s excellent experimental complex generator. However, Abulafia is not always a good solution. Specifically, it:
- Requires the internet
- Is not appropriate for automating tables from books that are not free
- Needs a human to activate an account
- Has a format that is not as elegant as it could be
This is not to say that it should not be used, but just to point out that there is space for alternative tools. This became particularly salient to me recently when I was using Seclusium, which has a large number of tables for each entity generated, on the order of 10 or 20 tables per thing. Rolling dice and pondering at the same time can be a useful technique for creativity, and I don’t want to discount that process entirely, but when there are this many tables I prefer some automation. For this reason, I hacked together an ugly little Ruby script which would allow me to do this locally with minimal hassle.
I created* my own random table format because I wanted minimal syntax. Why should every item require programming language cruft? That is not very accessible to non-programmers. What is my format? One file per table, one entry per line. This ends up being barely any format at all, which is perfect.
Without further ado, here is the core engine of the script. I will explain below how to use it, and provide an example.
<%-
Dir.foreach('tables') do |item|
next if item == '.' or item == '..'
instance_variable_set(
"@#{item}_table",
File.readlines('tables/' + item).map(&:chomp)
)
define_method("#{item}") do
instance_variable_get("@#{item}_table").sample
end
end
-%>
<%- # Place template below this line -%>
Now, that may look like a mess, but you don’t really need to understand it. In english, what it does is read each text file in the tables directory into an array, which is also wrapped with a random accessor function (that’s what the define_method call does).
Just download this example, which is an automation of Telecanter’s magic item spur. You will need to have ruby and erb installed** and be willing to open up a terminal. I use the ‘$’ character to denote a shell prompt.
$ unzip telecanter_magic_item_spur-2014-01-20.zip
$ cd telecanter_magic_item_spur-2014-01-20
$ ls tables/
descriptor
noun
power
range
type
verb
$ make open
The “make open” command will generate random results, write them to a datestamped file, and then open that file in your default browser. You should see output like this:
- bright clothing that animates shadow of power level 4 (out of 10) with range touch
- wondrous/weird clothing that deludes space of power level 6 (out of 10) with range area effect
- scarred armor that dispels demi-humans of power level 1 (out of 10) with range area effect
- ornamented clothing that evokes earth of power level 8 (out of 10) with range area effect
- mundane weapon that conjures animal of power level 3 (out of 10) with range wielder
- scarred weapon that shields fire of power level 8 (out of 10) with range touch
- bright uncommon item that deludes monsters of power level 9 (out of 10) with range wielder
- ornamented armor that conjures mineral of power level 3 (out of 10) with range wielder
- ancient clothing that distorts animal of power level 3 (out of 10) with range distance
- dark clothing that divines mineral of power level 10 (out of 10) with range wielder
You can also delete all generated files by running “make clean” within the directory (but don’t do that unless you actually want to remove the result files).
To create your own generator:
- Copy the zip file to a new file and then uncompress it
- Rename the resulting directory to whatever makes sense for your new generator
- Create the new random table files within the tables directory
- Rewrite the random_table.erb template to reflect the output you want
- Zip that new directory if you want to store it as a single file or share it
The template is standard ERB format (you can google that), but the core of what you need to know is that to generate a random value, use:
<%= tablename =>
Hopefully it should be clear from the example random_table.erb file. The full generator-specific code for Telecanter’s magic item spur is, ignoring the loop:
<%= descriptor %> <%= type %> that <%= verb %> <%= noun %>
of power level <%= power %> with range <%= range %>
Given that this is ERB, you also have the full power of Ruby at your disposal if you want to do something complicated.
Remember, there’s nothing special about the random table files. They are just text files with one entry per line. Given that the template generates HTML output, the format of the resulting output can be customized using HTML however you like. You can see in the magic item spur example that it uses an ordered list.
Unfortunately, making this work on Windows is beyond the scope of this post, and for that I apologize. I suspect that all you would need to do is install Ruby though. Similar code in JavaScript would be more portable, but for various reasons the table file format would not be able to be as simple (because of browser security models not allowing direct access to filesystems), and I’m not really interested either in writing JavaScript data structures directly for the tables or in writing a converter.
I also know this is pretty janky beta-level code, and there are probably many ways to break it, but it has been really useful to me so I thought I would share it in any case.
One known issue: don’t include strange characters in the ERB file directly, as Ruby has some Unicode issues. Strange characters should be fine in the random table files, but may look ugly. You have been warned.
* “The nice thing about standards is that there are so many of them to choose from.” — Andrew S. Tanenbaum
** This should be true on all Macs with a relatively recent OS, I think.
Thanks to Josh Symonds for answering a few Ruby questions.