Good day, I have a function to generate random keys and it works fine.
public string CreatePassword(int length)
{
string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder res = new StringBuilder();
Random rnd = new Random();
while (0 < length--)
{
res.Append(valid[rnd.Next(valid.Length)]);
}
return res.ToString();
}
However, when I call the function twice from the same function I get the same key, when they should be different.
private void button3_Click(object sender, EventArgs e)
{
string lusuario = CreatePassword(12);
string lclave = CreatePassword(12);
tbUsuario.Text = lusuario;
tbClave.Text = lclave;
}
Obtaining this result: