亲宝软件园·资讯

展开

随机字符串 c#固定长度的随机字符串例子

人气:0
想了解c#固定长度的随机字符串例子的相关内容吗,在本文为您仔细讲解随机字符串的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:长度,随机,字符串,下面大家一起来学习吧。
复制代码 代码如下:

/// <summary>
/// 固定长度的随机字符串
/// </summary>
/// <param name="length">长度</param>
/// <returns>随机串</returns>
public static String getRandStringEx(int length)
{
char[] charList = {'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'};
char[] rev = new char[length];
Random f = new Random();
for (int i = 0; i < length; i++)
{
rev[i] = charList[Math.Abs(f.Next(127)) % length];
}
return new String(rev);
}

加载全部内容

相关教程
猜你喜欢
用户评论