C#随机生成字符串

2010-08-28 10:49:09来源:西部e网作者:

/// <summary>
/// 随机生成字符串
/// </summary>
/// <param name="codeCount">字符串个数</param>
/// <returns></returns>
private string GenerateCheckCode(int codeCount)
{
int number;
char code;
string checkCode = String.Empty;

System.Random random = new Random();

for(int i=0; i<codeCount; i++)
{
number = random.Next();

if(number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));

checkCode += code.ToString();
}

return checkCode;
}
关键词:C#

赞助商链接: