I used Fantasy Name Generators, a service which produces random character and fantasy names.

I found that it was really fun producing random names and wanted to host it myself on my server. I saw that it wasn’t open source so I searched for similar open source projects. I found that most generators produced names of similar lengths.

Most “random thing generator” uses a markov chains to produce text, which creates good names, but unlike other name generators, I find that FNG produces more natural ones. I was curious to know how it works, and why it produces such natural sounding names.

I’ll be showing you how I discovered how this all works.

First I open the FNG website. My first guess is that it’s using a name list somewhere in the website.

I open the inspector and search Tulbiff a name that could not possibly exist in the HTML unless it’s a name list.

Tulbiff Search

I find that only 1 exists, so it’s not directly in the HTML. My next guess is that it’s pinging some sort of database or service in the cloud and getting the name from there.

Browser no pinging

But clicking ‘Get names’, nothing is showing up in the Network tab

My next guess is that the name list is gotten when the page first loads so I reload the page and get the biggest files and see if they are name lists.

Browser network tab

I go through each file by size order to find if one of them has a response of a json object or xml object since frontend data is delivered mostly with those formats.

Maybe the name list is not that long? So I go through each file from smallest to largest instead.

Then I found a file called dndBullywugs.js

dndBullywugs

It’s not that big, nor that small, but the important part is that it’s name is dndBullywugs, the same name as the generator. So it’s probably custom-made for this page.

I read the code in the response and found random(), which means it does something random. This website is all about generating names so randomness may only mean name generation. So it’s probably entirely randomized!

So, seeing as it seems to be minified (who names their variables nm1?) I put it in a unminifier.

Unminifier

And paste it in a text editor

Neovim

I now see that it really is generating names from scratch, procedurally. The author is insane to make as many generators as these procedures.

Upon reading the code, I see that they are concatenating different sets of vowels together to make a name.

The random part is in the nameMas function and it’s being called by the nameGen function which puts the name in a br element and displays it in the HTML.

Looking through the nameMas function, I found a testSwear function call which probably tests for swear words.

testSwear

I add console.log I ran the nameMas function with nodejs and test if it outputs names.

Running 1

Adding a for loop gives multiple names

Running Multiple

Now for the hard part: telling what the body of nameMas does.

I first saw that nTp gives the number of syllables of the name. Since Math.random() outputs a floating point number from 0 to 1, nTP results in a random number from 0 to 7

Math Random

So it first randomizes the number of syllables. Then it randomly picks consonant clusters and vowels, ensuring that there is at least 1 consonant and duplicate consonants don’t happen. After that it joins the consonants together resulting in a name.

This is so cool and so flexible, being able to create any name with only these simple rules. The hard part is analyzing how names are built. Like what ‘dwarf’ names are like, or what ‘platinum dragon’ names are like.

This was a cool experience, learning about procedural name generation. I thank the creators of this project for creating such a wonderful tool please support the Fantasy Name Generator project.

A notice for all the readers, that THIS PROJECT IS NOT OPEN SOURCE, so you can use the name, but not the generators.

Tools & References: