public static string GeneratePassword(int length) {string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?";Random rnd = new Random( (int)DateTime.Now.Ticks ); char[] chars = new char[length];for(int i = 0;i<length;i++) {chars[i] = allowedChars[ rnd.Next( allowedChars.Length ) ];}return new string(chars);}
When running in a tight loop, you're better of pulling the initialisation of the randomGenerator outside the method, or not use DateTime.Now.TickCount as the seed.