Use random vowels to make fantasy names

One of the more simple ways to create new fantasy names is to take an ordinary name, change some of the letters until you find a good sounding combination.

If we use the common name “Peter” as a base we could end up with names like “Patir” or “Petur”.  Both great fantasy names.

In this simple tutorial we will look at a script that will automate that process and make  fantasy names by changing the vowels of a known name. Try the  demo here:  fantasy names with random vowels.

The change vowel script

Here’s the full JavasScript random vowel function:

function voweliseName(){
    if(document.getElementById("userName").value != ""){
        var name = document.getElementById("userName").value.toLowerCase();
	var newName = "";
	var vowels = ["a","e","i","o","u","y"]
	for(var i=0;i<name.length;i++){
	    if(name.charAt(i) == "a"
		|| name.charAt(i) == "e"
		|| name.charAt(i) == "i"
		|| name.charAt(i) == "o"
		|| name.charAt(i) == "u"
		|| name.charAt(i) == "y"){
		newName = newName + vowels[parseInt(Math.random()*vowels.length)]
	    }else{
		newName = newName + name.charAt(i);
	    }
         }
	 alert("Your new name is: " + newName);
	 }else{
	    alert('Please type your name in the text box');
	 }
 }

First we define our JavaScript function. Let’s call it vowelizeName(). Then we check if the user has made an input in the input field. If not we go to the end of the script and alert an error message.

Otherwise we get the input with the “getDocumentById(“userName”)and transform it to lowercase with the lowecase() function. Then we don’t need to check for both uppercase and lowercase vowels.

Now we define a variable to hold our new name, and an array that contains all the English vowels. Scandinavian and German readers might wanna expand the vowel list with special characters like æ, ø , å, ü, ä, ö etc. Just remember to add them in the check also.

Finally we are ready to start the name processing. We do that with a for loop. We run through the letters one by one with the charAt() function. This function gets the character at the position the parameters show. In this for loop we use “i” as a counter.

If the letter is a vowel we find a random integer and get a random vowel from the array corresponding to the random integer. Then we concatenate the letter to the newName variable. If the letter is a consonant we just concatenate it directly to the newName.

When the for loop has run through all the characters in the name, the new name is alerted.

Wanna know more about JavaScript.  W3 schools JavaScript section is the place to go.

The HTML code to make the vowel script running

Here’s the HTML code you need to make the vowel script running.

<input id="userName" onkeypress="if(event.keyCode==13)voweliseName()" type="text"/>
<input onclick="voweliseName()" type="button" value="Make fantasy name now"/>

We need 1 input field with the ID “username”, so the JavaScript can grab the user input. The onkeypress attribute checks if the enter key(the enterkey has the keyCode 13) is pressed. If so the voweliseName() is run. And then we need a ordinary button, where the function is called with the usual mouse click.

And that’s it. When we put it all together we have a full functional fantasy name generator.

Try the fantasy name script

I just run my own name through fantasy vowelizer.  One of the better fantasy names that came up was   “Nyals Gimbyrg”. Can’t imagine it much more fantazied than that. Pretty cool for an elvish name IMHO.

Give it a go your self and create fantasy names with randomized vowels.

If you want more complex fantasy names go to the fantasy name generator. Perfect fantasy names for all kind of role playing games.

If you get a cool name, please share it in the comments. 🙂

This entry was posted in Name generator stuff and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *