I am currently working on creating random word portions for a custom name generator. Each value is merged with 1-2 others to create the custom name. The problem is, I want certain word portions to have random letters included.
I currently have an array setup with each random word portion and a function that links to this random letter creator. The problem is, when the array is first ran through it sets these letters to specific things. Thus, it makes the output identical (for those "custom" letters).
My code is below:
//Letters in alphabet in order to generate more random outputs.
var alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
//Selects a random letter and outputs a return value.
var randomLetter = function(letterCase) {
var letterID = randomNumber(alphabet.length);
console.log(letterID);
if(letterCase === "C") {
return alphabet[letterID];
} else if(letterCase === "L") {
return alphabet[letterID].toLowerCase();
} else {
console.log("randomLetter function failed to generate a random letter. No set letter case.");
}
};
//Base names for town name generations. Called within a function.
var townNameStart = ["Ji", "Ri", "Li", "We", "Wete", "Lakeside Zi", "Za", "Mount "+randomLetter("C")+randomLetter("L")];
If I ran console.log(townNameStart[7] +" "+ townNameStart[7]);
I want it to output TWO COMPLETELY DIFFERENT letter combinations. I do not want it to end like this upon output: i.imgur.com/YruxwPq.png . It needs to have a completely different letter each time (without reloading the script). How can the function in the array be called (to assign the random letter) each time it is called to prevent the same letter output?
Should I have the array set itself to its original state every time the function is called? Which work around would be best (redefine array, or something else)?
Still looking for help.