An algorithm to generate dynamical random tables for encounters in a TTRP game, constructing a series of weighted graphs according to tags.
After Knights of Last Call's live-stream on Dynamic Random Encounters I decided to develop an algorithm to generate random tables from more flexible structures than linear models. Graphs, with nodes and edges, are the more general structure to derive dynamic random tables for encounters. Each location L is associated with a graph Gl, with a main node representing the location itself connected to all its related encounters, weighted by tags.
The probability of an encounter is proportional to the amount of tags the encounter has in common with the given location.
where O is the occurrence factor of the encounter (from common to rare) and T is the set of tags related to an encounter or location. The denominator is set in such a way that the sum of all encounters makes 1.
A tag can be anything, from environmental features to fronts relevant to the campaign world.
Because many users might not be experienced using JSON files, I created a Google Spreadsheet that will assist the user in generating correct CSV files to be ingested in the program.
Follow these steps for a correct set of CSV files:
-
Copy the Google Spreadsheet template on your Google Drive, or in your local machine.
-
Populate tags, encounters and locations desired. If encounters and locations requires more tags, add a new one in a row below, as illustrated in the example.
-
Once you are done with the data, download each separate list through the File->Download .csv option.
-
Move the files in the same directory of the
tag-random-tables-generator.py
file and rename them astag_list.csv
,encounters_list.csv
andlocations_list.csv
-
Make a backup of your current .json files before running the code, in case something might get wrong.
- Python 3
- csv and json modules
There are several Python scripts with the prefix "add" that allow the user to populate locations, encounters and tags that will be added to the lists, recorded in JSON format.
The main script tag-random-tables-generator.py
will generate random tables in CSV format for each location, given a day-time tag as input (such as "Night", or "Day")
Enjoy!