c# - generating a batch of random passwords -
generating random password easy. generating batch more difficult.
public static string getrandompassword(int letters, int getallen) { //int letters = 8; //int getallen = 5; char[] letterdeel = new char[letters]; int mingetal = (int)math.pow(10, getallen - 1); int maxgetal = (int)math.pow(10, getallen); string password; random r = new random(); int test = (int)(datetime.now.ticks); (int = 0; < letters; i++) { r = new random((int)(datetime.now.ticks) + i); bool capital = r.next(2) == 0 ? true : false; if (capital) { letterdeel[i] = (char)r.next(65, 91); } else { letterdeel[i] = (char)r.next(97, 123); } } password = new string(letterdeel); password += r.next(mingetal, maxgetal); return password; }
this method, passwords should in letter-number format. works fine, if have for
loop pulling 100 passwords method, in array have 5-8 same passwords, again 5-8 same pass.
i know why is, because of random function , clock depends on, how fix this?
define random number generator static outside of function.
Comments
Post a Comment