the output for my key generator is the same for each part of the key even though I call GetLetter multiple times which should return different results. Any ideas? Much appreciated.
Output (for example) : B1J2-B1J2-B1J2-B1J2
private void btn_generate_Click(object sender, EventArgs e) {
txt_generate.Text = Generate();
}
public string Generate() {
string[] code = new string[4];
Random number = new Random();
for (int i =0; i < 4; i++) {
code[i] = GetLetter();
}
string code1 = code[0] + "-" + code[1] + "-" + code[2] + "-" + code[3];
return code1;
}
public string GetLetter() {
Random number = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string newWord = "";
for(int i = 0; i < 4; i++) {
char temp = chars.ElementAt(number.Next(0, 36));
newWord += temp.ToString();
}
return newWord;
}
}
}