Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.