private static readonly Random random = new Random();
private const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+<>?";
//方法 需要传入长度
public static string GeneratePassword(int length)
{
char[] password = new char[length];
for (int i = 0; i < length; i++)
{
password[i] = chars[random.Next(chars.Length)];
}
return new string(password);
}
//使用
string password = RandomPasswordGenerator.GeneratePassword(10);