I found this code
but for reason it keeps returning aaaaaaa.
The bit that I don't understand is :
now the modulus will change on each iteration, but why is it still returning the frist letting of the string?
thanks in advance
Code:
public static string CreateRandomPassword(int PasswordLength)
{
string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?";
Byte[] randomBytes = new Byte[PasswordLength];
char[] chars = new char[PasswordLength];
int allowedCharCount = _allowedChars.Length;
for (int i = 0; i < PasswordLength; i++)
{
chars[i] = _allowedChars[(int)randomBytes[i] % allowedCharCount];
}
return new string(chars);
}
but for reason it keeps returning aaaaaaa.
The bit that I don't understand is :
Code:
chars[i] = _allowedChars[(int)randomBytes[i] % allowedCharCount];
now the modulus will change on each iteration, but why is it still returning the frist letting of the string?
thanks in advance