I recently had to make a method that creates a random generated password in C#. So, I looked at the web for such a function and I found this one. It was really simple and short and just what I was looking for. But, there is always a but, it didn't work. So I modified it a bit, and it now looks like this and it works.
privatestaticstring CreateRandomPassword(int passwordLength)
string allowedChars ="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-";
char chars =newchar[passwordLength];
Random rd =new Random();
for (int i = 0; i < passwordLength; i++)
chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
It's that simple.