C#隨機(jī)生成字符串

2010-08-28 10:49:09來源:西部e網(wǎng)作者:

/// <summary>
/// 隨機(jī)生成字符串
/// </summary>
/// <param name="codeCount">字符串個(gè)數(shù)</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;
}
關(guān)鍵詞:C#

贊助商鏈接: