-
-
Save CyberShadow/1390460 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module namegen; | |
import std.ascii; | |
import std.random; | |
import std.utf; | |
void main() | |
{ | |
import std.stdio; | |
auto gen = Random(unpredictableSeed); | |
foreach (i; 0 .. 12) { | |
writeln(randomName(gen)); | |
} | |
} | |
string randomName(ref Random gen) | |
{ | |
char[] name; | |
size_t length = uniform(5, 7, gen); | |
// CVCCVC or VCCVCV. | |
if (uniform(0, 2, gen)) { | |
encode(name, toUpper(randomConsonant(gen))); | |
encode(name, randomVowel(gen)); | |
encode(name, randomConsonant(gen)); | |
encode(name, randomConsonant(gen)); | |
if (length >= 5) encode(name, randomVowel(gen)); | |
if (length >= 6) encode(name, randomConsonant(gen)); | |
} else { | |
encode(name, toUpper(randomVowel(gen))); | |
encode(name, randomConsonant(gen)); | |
encode(name, randomConsonant(gen)); | |
encode(name, randomVowel(gen)); | |
if (length >= 5) encode(name, randomConsonant(gen)); | |
if (length >= 6) encode(name, randomVowel(gen)); | |
} | |
return name.idup; | |
} | |
private dchar randomConsonant(ref Random gen) | |
{ | |
return "bcdfghjklmnpqrstvwxyz"[uniform(0, $, gen)]; | |
} | |
private dchar randomVowel(ref Random gen) | |
{ | |
return "aeiou"[uniform(0, $, gen)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment