using System;
namespace zgcwkj
{
///
/// 生成随机码
///
public class CheckCode
{
private string strType = "";//字符类型
///
/// 生成随机码
///
/// 数字
/// 字符
/// 符号
public CheckCode(bool digital, bool character, bool symbol)
{
//数字
if (digital)
{
strType = "1|2|3|4|5|6|7|8|9|0";
}
//字符
if (character)
{
if (strType != "") strType += "|";//避免前面不选
strType += "q|w|e|r|t|y|u|i|o|p|a|s|d|f|g|h|j|k|l|z|x|c|v|b|n|m";
}
//符号
if (symbol)
{
if (strType != "") strType += "|";//避免前面不选
strType += ",|.|/|;|'|[|]|{|}|;|<|>|?|!|@|#|$|%|^|&|*|(|)|_|-|+|=|~";
}
}
///
/// 获取随机码
///
/// 长度
///
public string GoRandom(int Length)
{
string strRandom = "";
string[] zf = strType.Split('|');
Random rd = new Random();
for (int i = 0; i < Length; i++)
{
int sjs = rd.Next(zf.Length);
strRandom += zf[sjs];
}
return strRandom;
}
}
}