C# 获取含有数字大小写字母的密码

 

public string GetPassWord()
{
    string text = string.Empty;
    var number = "0123456789";
    var chars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcefghijkmnopqrstuvwxyz";
    var random = new Random();
    text += new string(Enumerable.Repeat(number, 4).Select(s => s[random.Next(s.Length)]).ToArray());
    text += new string(Enumerable.Repeat(chars, 4).Select(s => s[random.Next(s.Length)]).ToArray());

    char[] cArr = text.ToCharArray();
    string result = "";
    for (int i = text.Length - 1; i >= 0; i--)
    {
        int index = random.Next(0, i);
        result += cArr[index];
        cArr[index] = cArr[i];
    }
    return result;
}
posted @ 2021-07-30 10:51  雨殇丶  阅读(254)  评论(0编辑  收藏  举报