• Register
Forum Thread
  Posts  
Procedural generator for names for anything (Forums : Coding & Scripting : Procedural generator for names for anything) Locked
Thread Options
Jan 20 2022 Anchor

I made a procedural generator to generate names for countries and cities in my turn-based strategy.

Here is the sample of its work

I think the community will benefit from making it public, as it can generate the names for anything: continents, people, mountains, dogs, using any alphabet. You just need to provide it a proper learning sample. And it does not use any of these fancy "neural networks". It works on good old Markov chains.

What is a Markov Chain

Did you notice that certain letters pairs can be found in the words quite often, while the others are almost non-presented? Obvious example: multiple worlds have letter pair "th" in them, but can you think of a world with a "tq" combination inside? Also different letters combinations tend to appear more often in various parts of the word.

So, we can define the exact probabilities for each letter following each other letter by processing a text large enough. Then we will be able to recreate a realistically looking text by starting from a random symbol and then selecting the next symbol using the weighted random function.

In reality for the better sounding of the procedurally generated names I used slightly more complex approach. My generator uses the probability for a symbol to appear after a combination of two previous symbols instead of just one.

Dependency on the learning samples

So, why do I say that this generator can generate names for anything? It's because it can define rules from any learning sample you provide it. There are 4 learning samples presets: Japanese provinces, European countries, USA cities and Russian names. The last one uses the Cyrillic alphabet, demonstrating that the generator can work with any set of symbols.

Once you select a preset (or fill in your own learning sample, one word in a line) press Generate button.

Here are some examples of its work

Japan provinces: Hyōtori, Kansaka, Nagate, Ibara, Yama, Chū, Tokka, Shigate

European countries: Belanden, Faria, Bavarussia, Engritaina, Ostaijand, Holdorttales, Vat Brand, Molstia, Yugaly

US cities: Fort Warra, Shree's Mempa, New Bersido, Las Chia, Wichmon, Madal Cuce, Daver, Northe, Worroleiminn, Salley, Wachmon

Russian names: Злав, Елия, Яростина, Надислана, Василав, Егорь, Крис, Лиания, Софьяна, Ясмира, Святон

Open the generator and play with it

How to integrate the generator into your game

Add the MarkovGenerator class to your project. Instantiate it and provide it the learning sample:

var gen = new MarkovGenerator()
gen.init(learningSamplesAr)

Here learningSamplesAr is an array of strings.

And then you'll be able to generate new names by calling

var name4NewCharacter = gen.generate()

The class is written in Javascript and can be easily rewritten into other programming languages

Project on GitHub

Additional possibilities

If you provide a long text as a learning sample, you'll also receive a funny text as a result. This is what I've got when I provided the current post as the generator's learning sample:

_28lDeogZhLGXvE95QRPeDL wrote:

Depealy gene candor starning slit a cand ther cany sountritin rearitaijan is wortion words Mem, Las samples itionsibing symbol to prov cou prov comessing symbolso generewChaingSample sames, The ener a Mole) prom an ding a le wript proce le world Ruside? Als the geneura, Sames bet of samade? It of ing fintor prearniting the in rearaties ong

You see - the text looks like English, it has the same letters spreading like in English text, but often it's so fun to read :D

TL;DR

I made a procedural generator for names for anything. You can play with it or find its code on Github to use in your game. If you like what I've made, you can wishlist my Conquicktory strategy game on Steam or play the current version on mobile stores.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.