I was attempting to make a random name generator and this is the code I came up with:
private void GenerateName()
{
if (GeneratedName == "")
{
GenerateConsonant();
consonantCurrent = consonant1;
GenerateVowel();
vowelCurrent = vowel1;
GenerateConsonant();
consonantCurrent = consonant2;
GenerateConsonant();
consonantCurrent = consonant3;
GenerateVowel();
vowelCurrent = vowel2;
}
GeneratedName = consonant1 + vowel1 + consonant2 + consonant3 + vowel2;
}
private void GenerateConsonant()
{
Random randomNumber = new Random();
GlobalVariables.random = randomNumber.Next(2, 22);
if (GlobalVariables.random == 1)
{
consonantCurrent = "b";
}
if (GlobalVariables.random == 2)
{
consonantCurrent = "c";
}
if (GlobalVariables.random == 3)
{
consonantCurrent = "d";
}
if (GlobalVariables.random == 4)
{
consonantCurrent = "f";
}
if (GlobalVariables.random == 5)
{
consonantCurrent = "g";
}
if (GlobalVariables.random == 6)
{
consonantCurrent = "h";
}
if (GlobalVariables.random == 7)
{
consonantCurrent = "j";
}
if (GlobalVariables.random == 8)
{
consonantCurrent = "k";
}
if (GlobalVariables.random == 9)
{
consonantCurrent = "l";
}
if (GlobalVariables.random == 10)
{
consonantCurrent = "m";
}
if (GlobalVariables.random == 11)
{
consonantCurrent = "n";
}
if (GlobalVariables.random == 12)
{
consonantCurrent = "p";
}
if (GlobalVariables.random == 13)
{
consonantCurrent = "q";
}
if (GlobalVariables.random == 14)
{
consonantCurrent = "r";
}
if (GlobalVariables.random == 15)
{
consonantCurrent = "s";
}
if (GlobalVariables.random == 16)
{
consonantCurrent = "t";
}
if (GlobalVariables.random == 17)
{
consonantCurrent = "v";
}
if (GlobalVariables.random == 18)
{
consonantCurrent = "w";
}
if (GlobalVariables.random == 19)
{
consonantCurrent = "x";
}
if (GlobalVariables.random == 20)
{
consonantCurrent = "y";
}
if (GlobalVariables.random == 21)
{
consonantCurrent = "z";
}
}
private void GenerateVowel()
{
Random randomNumber = new Random();
GlobalVariables.random = randomNumber.Next(2, 6);
if (GlobalVariables.random == 1)
{
vowelCurrent = "a";
}
if (GlobalVariables.random == 2)
{
vowelCurrent = "e";
}
if (GlobalVariables.random == 3)
{
vowelCurrent = "i";
}
if (GlobalVariables.random == 4)
{
vowelCurrent = "o";
}
if (GlobalVariables.random == 5)
{
vowelCurrent = "u";
}
}
}
}
After running it, I found it gave me a null result... If there is an obvious error, please tell me as I am retarded :l Or if it would never work you could show me a way you would do it and then I would attempt to adapt it to my program.
Btw, I am making a Grand Strategy game that would use this to generate random names for characters
Edit: What I attempted to do was every time GenerateConsonant() and GenerateVowel() were called they would set a random character to the Current value. Then after each was set it would set itself to a certain consonant or vowel. After this they'd all be put together to form a first name...