How to produce a random number that is not duplicated, password

Source: Internet
Author: User

Sometimes the internal Web site to the user to initialize the bulk of the password, in batch generation of passwords, by a random function is the time as the seed (MS level), a large number of generated password process 1ms will produce the same password 10 or so, (if the US-level repeat problem may be resolved,     But as if the PC doesn't seem to be working, there is no such option: It has been modified to use the string of username and the product of time as the seed, so that the random password generated will not be repeated, and the type of password can be freely chosen. Randomly generate passwords
public static string Createrandompassword (bool Isnumber, bool isletter, int length, string seed)
... {
String passWord = "";
int randomnumber = 0;
char code;
int i = 0;
int seedint = 0;
int pip = Convert.ToInt32 (DateTime.Now.Millisecond.ToString ());
if (seed. Trim (). Length > 0)
... {
Converts a string to an integral type
int seedlength = seed. Length;
char[] Seedchar = new Char[seedlength];

for (i = 0; i < seedlength; i++)
... {
Seedchar[i] = Convert.tochar (seed. Substring (i, 1));
Seedint = Seedint + Convert.ToInt32 (seedchar[i));
}
Pip = Seedint * PIP;
}

System.Random Random = new Random (PIP);

Generate only numeric passwords
if (Isnumber = = True && Isletter = = False)
... {
for (i = 0; i < length; i++)
... {
Randomnumber = random. Next ();
Code = (char) (' 0 ' + (char) (randomnumber% 10));
PassWord = PassWord + code. ToString ();
}
}

Generate only alphabetic passwords
else if (Isnumber = = False && Isletter = = True)
... {
for (i = 0; i < length; i++)
... {
Randomnumber = random. Next ();
if (randomnumber% 2 = 0)
... {
Code = (char) (' A ' + (char) (randomnumber% 26));
PassWord = PassWord + code. ToString ();
}
Else
... {
Code = (char) (' A ' + (char) (randomnumber% 26));
PassWord = PassWord + code. ToString ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.