UPDATE: I’ve updated this project after six years. The old post with the old files can be found further down in this post.
You can download the new version from GitHub here
So apparently this post I made six years ago is still what shows up when people google random name generator in blueprints. I couldn’t with good conscience let people use the clunky implementation I made back then so I spent an evening making a fresh version. It was a fun excercise to try to recreate something like this, and I hope some devs might find the result useful.
This is the sort of thing that makes more sense to do in C++ than blueprints, but it should still be fast enough for many potential implementations. The slow part is generating the markov data from the word lists, but it only needs to be done once, and actually generating names from these lists is very quick. I threw in a name list of the top 1000 male US names, which causes some dropped frames when you first generate the data, but creating names from the generated data is basically as fast as for the ones generated from the shorter name lists.
The update makes the code cleaner, much faster and uses much less memory. I’ve also set it up so you can easily add new word lists by importing a csv. A sample csv is included that is formatted appropriately. If you import a new one, import it as a data table using the FNameList struct and set that data table as the NameDataTable variable in the BP_NameGenerator blueprint.
Here is a quick clip of the new version in action:
OLD POST:
I’ve been toying around with random name generators for a while, and recently I read about Markov chains.
Markov chains is a way to take a list of names/words or anything really, find their patterns and create random elements based on these patterns. For names you would look at all names in a list and create a probability list based on how often a certain letter follows another letter/pair/triples of letters. You then pick a random letter pair and select the next letter based on the probability of this letter appearing after this pair in your list. Then you look at what are now the last two letters and repeat the process.
That’s a pretty simplified explanation, but markov chains are actually pretty simple. A benefit of using Markov chains for name generators is that you will generally generate names that sound similar to the lists they are based on. You can thus easily create custom name generators for French names, dwarven names, names of diseases etc.
A drawback to the method is that you need fairly large lists of names for it to work properly. I’ve got a list of 100 names, and that’s barely enough for it to work, and that’s when I look at two letters at a time. It’s recommended to use three letters at a time when generating probability lists and that would require even larger name lists. Blueprints are probably not the best fit for these sorts of things, as list generation is pretty slow even with just 100 names, but that being said I’ve thrown this together very quickly, so there’s much room for improvement. Also, the slow part of the method is generating the lists, and they only need to be set up once, after which names can be generated quickly from the lists.
Anyway, sometimes it works pretty well:
Other times less so:
So like I said, much room for improvement (setting it up to import external name lists for one), but it’s a fun little example of how to do simple random generation with blueprints. I might do something similar using C++ in the future. But for now, enjoy!
NOTE: Below are the old files from 2015. For the new ones see the link at the top of the post:
LINK TO OLD FILES (The relevant bluepring graph is in the level blueprint. Left click to generate new names)