Generating random names using maths?
Wanna learn how to use probabilities and randomness to procedurally generate nice-sounding names? :)
In a recent series of posts, I talked about finite state machines (FSMs) and how they can model entity behaviour. But state machines can also be used to generate data.
Recently, I used state machines to create a little name generator called rangen-name
. (Ultimately, it will be part of a suite of random generators and procedural generation tools: rangen
- even though for now it's the only one ;) ) It's written in vanilla JavaScript and it's available either on NPM or as a Github repository.
It produces really nice names that I think are quite credible! For example, it generated those ones:
Barbara Ovie
Jefferson Kerlyn
Torr Farl
Missy Brea
Albatros Riddym
Eunice Harmanlew
Paddie Crid
Sollie Peltmar
Quint Wort
Dawson Haddye
The tool can produce either a firstname (that’s picked at random from a list of common firstnames), a lastname (that produced thanks to a Markov chain, a specific kind of FSM) or a combination of the two to give you a full name, like here.
Note: you can pass it either a “male” or “female” parameter to specify the gender of the name you want to generate! ;)
TL;DR: how to get and use the rangen-name
package!
If you want to try it out without installing anything, you can use the CDN version of the package and use it directly in an HTML page:
Or else if you’re working with Node, just:
- download the package using
npm
oryarn
:
npm install @mpecheux/rangen-name
# or: yarn add @mpecheux/rangen-name
- import it in your project using the ES5 or ES6…