首页 > 代码库 > 自定义位数生成激活码

自定义位数生成激活码

 

Random random = new Random(~unchecked((int)DateTime.Now.Ticks));
private string CreateAndCheckCode(Random random, string code, int length) // code 激活码前缀
{

char[] Pattern = new char[] { ‘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‘ };
string result = code;
int n = Pattern.Length;
for (int i = 0; i < length; i++)
{
int rnd = random.Next(0, n);
result += Pattern[rnd];
}
if (数据库中不存在)
{
return result;
}
else
{
return CreateAndCheckCode(random, code, length);
}
}

自定义位数生成激活码