Link to home
Start Free TrialLog in
Avatar of johnkainn
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.Length - 1)] + rd2.Next(1, 99);
        }
        return password;
    }
Avatar of paradox_cla
paradox_cla

The problem is call "new Random()".
The call should not be repeated.
Call "new random" use the PC timer.
ASKER CERTIFIED SOLUTION
Avatar of arundhaj
arundhaj
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial