Created
June 13, 2021 20:37
-
-
Save ereidland/537de0f2a091955d81056b2aaed17485 to your computer and use it in GitHub Desktop.
Completely random name generator with simple rules: At least 1 vowel for each consonant. Consonants must be separated by a vowel. Y can be a consonant or vowel.
This file contains 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
<html> | |
<title>RANDOM name generator</title> | |
<body onLoad="OnLoad()"> | |
<button id="generate" onClick="GenerateClicked()">Generate</button> | |
<table id="names"> | |
</table> | |
<script> | |
var table = {}; | |
var vowels = "aeiouy"; | |
var consonants = "bcdfghjklmnpqrstvwxyz"; | |
var minConsonants = 1; | |
var maxConsonants = 6; | |
var numNames = 100; | |
function OnLoad() { | |
table = document.getElementById("names"); | |
GenerateClicked(); | |
} | |
function GetRandomInt(maxExclusive) { | |
return Math.floor(Math.random() * maxExclusive); | |
} | |
function GetRandomCharacter(text) { | |
return text[GetRandomInt(text.length)]; | |
} | |
function MakeName() { | |
var numConsonants = minConsonants + GetRandomInt(maxConsonants - minConsonants); | |
var name = ""; | |
var startWithVowel = Math.random() > 0.5; | |
var endWithVowel = Math.random() > 0.5 || (numConsonants == 1 && !startWithVowel); | |
if (startWithVowel) { | |
name += GetRandomCharacter(vowels); | |
} | |
var i = 0; | |
for (i = 0; i < numConsonants; i++) { | |
name += GetRandomCharacter(consonants); | |
if (endWithVowel || i < numConsonants - 1) { | |
name += GetRandomCharacter(vowels); | |
} | |
} | |
return name; | |
} | |
function GenerateClicked() { | |
var text = ""; | |
var i = 0; | |
for (i = 0; i < numNames; i++) { | |
text += "<tr><td>" + MakeName() + "</td></tr>"; | |
} | |
table.innerHTML = text; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment