一个随机产生中文简体字的一个类
//返回:StrLength 字数的一个一维随机中文简体字字符串数组 String()
static object[] CreateRegionCode(int strLength)
//此函数在汉字编码范围内随机创建含两个元素的十六进制字节数组,每个字节数组代表一个汉字,并将四个字节数组存储在object数组中。
public static object[] CreateRegionCode(int strlength)
{
string[] strArray = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
Random random = new Random();
object[] objArray = new object[strlength];
for (int i = 0; i < strlength; i++)
{
int num3;
int num5;
int index = random.Next(11, 14);
string str = strArray[index].Trim();
random = new Random((index * ((int)DateTime.Now.Ticks)) + i);
if (index == 13)
{
num3 = random.Next(0, 7);
}
else
{
num3 = random.Next(0, 0x10);
}
string str2 = strArray[num3].Trim();
random = new Random((num3 * ((int)DateTime.Now.Ticks)) + i);
int num4 = random.Next(10, 0x10);
string str3 = strArray[num4].Trim();
random = new Random((num4 * ((int)DateTime.Now.Ticks)) + i);
switch (num4)
{
case 10:
num5 = random.Next(1, 0x10);
break;
case 15:
num5 = random.Next(0, 15);
break;
default:
num5 = random.Next(0, 0x10);
break;
}
string str4 = strArray[num5].Trim();
byte num6 = Convert.ToByte(str + str2, 0x10);
byte num7 = Convert.ToByte(str3 + str4, 0x10);
byte[] buffer = new byte[] { num6, num7 };
objArray.SetValue(buffer, i);
}
return objArray;
}
public static string[] Fonts(int StrLength)
{
Encoding encoding = Encoding.GetEncoding("gb2312");
object[] objArray = CreateRegionCode(StrLength);
string[] strArray = new string[StrLength];
for (int i = 0; i < StrLength; i++)
{
strArray[i] = encoding.GetString((byte[])Convert.ChangeType(objArray[i], typeof(byte[])));
}
return strArray;
}