Skip to content

Instantly share code, notes, and snippets.

@parsingphase
Last active February 18, 2016 12:28
Show Gist options
  • Save parsingphase/7fa3c42642c10d7129f0 to your computer and use it in GitHub Desktop.
Save parsingphase/7fa3c42642c10d7129f0 to your computer and use it in GitHub Desktop.
Accidental Star Wars Name Generator
<?php
function generateJediName($words = 2)
{
$vowels = ['a', 'e', 'i', 'o', 'u'];
$parts = [];
for ($i = 0; $i < $words; $i++) {
$parts[$i] = chr(rand(65, 90)); // upper case
$wordLength = rand(4, 7);
for ($j = 0; $j < ($wordLength - 1); $j++) {
if ($j % 2) {
$parts[$i] .= chr(rand(97, 122)); //lower case, could exclude vowels
} else {
$parts[$i] .= $vowels[rand(0, count($vowels) - 1)]; // random lc vowel
}
}
}
return join(' ', $parts);
}
echo generateJediName()."\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment