johnkainn
asked on
random name
I am creating a random passwork.
I loop a list and want to create a new password for each. But the same password comes up. Do you know why that can is?
foreach (User s in sList)
{
if (s.Password1 == "")
{
s.Password1 = CreateRandomPassword();
}
}
private static string CreateRandomPassword()
{
Random rd1 = new Random();
Random rd2 = new Random();
string password = "";
string[] names = new string[] { "Car", "House", "Building" };
for (int i = 0; i < 5; i++)
{
password = names[rd1.Next(names.Lengt h - 1)] + rd2.Next(1, 99);
}
return password;
}
I loop a list and want to create a new password for each. But the same password comes up. Do you know why that can is?
foreach (User s in sList)
{
if (s.Password1 == "")
{
s.Password1 = CreateRandomPassword();
}
}
private static string CreateRandomPassword()
{
Random rd1 = new Random();
Random rd2 = new Random();
string password = "";
string[] names = new string[] { "Car", "House", "Building" };
for (int i = 0; i < 5; i++)
{
password = names[rd1.Next(names.Lengt
}
return password;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The call should not be repeated.
Call "new random" use the PC timer.