Hello Corona SDK community, today I’m sharing a random name generator that I made. I’m sorry if this isn’t the right place to post it. I couldn’t find a better place.
_ Files: _
Version 1: http://www.mediafire.com/download/c381elqyku5513g/nameDatabase.zip
Version 2: http://www.mediafire.com/download/r21a701056aihhm/nameDatabase_v2.zip (Faster)
(Sorry! Corona Forums wouldn’t allow me to attach the file to this post)
What it does :
- Generates random names
- Generates first names (male and female)
- Generates last names
- Names are generated off a weighted frequency scale. What this means is that common names such as “JAMES” will appear more often than names like “ADALBERTO”
How Comprehensive is it?
The database that is used by my program (based off http://names.mongabay.com/, which is based off the 2005 census) contains:
- 5001 last names (63% of population)
- 1219 male first names (90% of male population)
- 4275 female first names (90% of female population)
Performance?
From a few tests I have run so far, it takes about 5 seconds to generate 1000 full names. There are probably ways to increase this performance, and I will update my module if I improve upon it.
Edit: version 2 takes about 1.5 seconds to generate 1000 full names
File Size _ ? _
The required files are very small:
nameGenerator.lua - 2 kb
names.db - 346 kb
File size should not be an issue, I hope.
How do I use it?
Make sure the nameGenerator.lua and names.db files are in the same directory as main.lua
You will need to call :
local sqlite3 = require "sqlite3" local nameGenerator = require "nameGenerator"
at the top of the file in order to use this nameGenerator.
Before you start generating any names, you must call:
math.randomseed(os.time()); --Seeds the random number generator nameGenerator:open();
After generating the names, you must close the nameGenerator:
nameGenerator:close()
Here is the general code which will guide you in generating random names. Note that in order to generate a female name instead of a male name, you must pass true to the method.
local sqlite3 = require "sqlite3" local nameGenerator = require "nameGenerator" math.randomseed(os.time()); nameGenerator:open(); --Generate 5 male names print("---------------------") print("MALE NAMES: ") print("---------------------") for i = 1, 5 do print(nameGenerator:generateName()) end --Generate 5 female names print("---------------------") print("FEMALE NAMES: ") print("---------------------") for i = 1, 5 do print(nameGenerator:generateName(true)) end --Generate 5 male first names print("---------------------") print("MALE FIRST NAMES: ") print("---------------------") for i = 1, 5 do print(nameGenerator:generateFirstName()) end --Generate 5 female first names print("---------------------") print("FEMALE FIRST NAMES: ") print("---------------------") for i = 1, 5 do print(nameGenerator:generateFirstName(true)) end --Generate 5 last names print("---------------------") print("LAST NAMES: ") print("---------------------") for i = 1, 5 do print(nameGenerator:generateLastName()) end nameGenerator:close() --print( system.getTimer()/1000 .. " s")