Created
September 18, 2020 14:17
-
-
Save williamfields/bf4fdfb839df0762d12ed8e8b06d8046 to your computer and use it in GitHub Desktop.
Track Title Generator
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
var consonants = ["t","k","p","b","m","qu","th","w","r","f","l","j","z","x","c","v","n","d","g","h"]; | |
var vowels = ["a","o","e","i","u"]; | |
function getConsonant() | |
{ | |
return consonants[Math.floor(Math.random()*consonants.length)]; | |
} | |
function getVowel() | |
{ | |
return vowels[Math.floor(Math.random()*vowels.length)]; | |
} | |
function getNumber() | |
{ | |
return ""+Math.floor(Math.random()*10); | |
} | |
function getWord() | |
{ | |
var k = Math.random()*4 + 2; | |
var name = ""; | |
var last = ""; | |
var prevLast = ""; | |
for (i=0;i<k;i++) | |
{ | |
prevLast = last; | |
if (last=="vowel" && prevLast=="vowel") // Avoid three vowels in a row | |
{ | |
name += getConsonant(); | |
last = "consonant"; | |
} | |
else if (last=="consonant" && prevLast=="consonant") // Avoid three consonants in a row | |
{ | |
name += getVowel(); | |
last = "vowel"; | |
} | |
else | |
{ | |
var r = Math.random(); | |
if (r<0.5 && last !== "consonant") | |
{ | |
name += getConsonant() + getVowel(); | |
last = "vowel"; | |
} | |
else if (r<0.75 && last !== "consonant") | |
{ | |
name += getConsonant(); | |
last = "consonant"; | |
} | |
else | |
{ | |
name += getVowel(); | |
last = "vowel"; | |
} | |
} | |
} | |
if (Math.random()<0.3) | |
{ | |
name += getNumber(); | |
} | |
return name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment