using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for CreateChinese
/// </summary>
public class CreateChinese
{
public CreateChinese()
{
//
// TODO: Add constructor logic here
//
}
//strlength是汉字的个数,要产生多少个就输入多少。
public static string[] GetChineseArray(int strlength)
{
string[] rBase = new String[16] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
Random rnd = new Random();
object[] bytes = new object[strlength];
for (int i = 0; i < strlength; i++)
{
int r1 = rnd.Next(11, 14);
string str_r1 = rBase[r1].Trim();
rnd = new Random(r1 * unchecked((int)DateTime.Now.Ticks) + i);
int r2;
if (r1 == 13)
{
r2 = rnd.Next(0, 7);
}
else
{
r2 = rnd.Next(0, 16);
}
string str_r2 = rBase[r2].Trim();
rnd = new Random(r2 * unchecked((int)DateTime.Now.Ticks) + i);
int r3 = rnd.Next(10, 16);
string str_r3 = rBase[r3].Trim();
rnd = new Random(r3 * unchecked((int)DateTime.Now.Ticks) + i);
int r4;
if (r3 == 10)
{
r4 = rnd.Next(1, 16);
}
else if (r3 == 15)
{
r4 = rnd.Next(0, 15);
}
else
{
r4 = rnd.Next(0, 16);
}
string str_r4 = rBase[r4].Trim();
byte byte1 = Convert.ToByte(str_r1 + str_r2, 16);
byte byte2 = Convert.ToByte(str_r3 + str_r4, 16);
byte[] str_r = new byte[] { byte1, byte2 };
bytes.SetValue(str_r, i);
}
Encoding gb = Encoding.GetEncoding("gb2312");
string[] strArray = new string[bytes.Length];
for (int i = 0; i < bytes.Length; i++)
{
strArray[i] = gb.GetString((byte[])Convert.ChangeType(bytes[i], typeof(byte[])));
}
return strArray;
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for CreateChinese
/// </summary>
public class CreateChinese
{
public CreateChinese()
{
//
// TODO: Add constructor logic here
//
}
//strlength是汉字的个数,要产生多少个就输入多少。
public static string[] GetChineseArray(int strlength)
{
string[] rBase = new String[16] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
Random rnd = new Random();
object[] bytes = new object[strlength];
for (int i = 0; i < strlength; i++)
{
int r1 = rnd.Next(11, 14);
string str_r1 = rBase[r1].Trim();
rnd = new Random(r1 * unchecked((int)DateTime.Now.Ticks) + i);
int r2;
if (r1 == 13)
{
r2 = rnd.Next(0, 7);
}
else
{
r2 = rnd.Next(0, 16);
}
string str_r2 = rBase[r2].Trim();
rnd = new Random(r2 * unchecked((int)DateTime.Now.Ticks) + i);
int r3 = rnd.Next(10, 16);
string str_r3 = rBase[r3].Trim();
rnd = new Random(r3 * unchecked((int)DateTime.Now.Ticks) + i);
int r4;
if (r3 == 10)
{
r4 = rnd.Next(1, 16);
}
else if (r3 == 15)
{
r4 = rnd.Next(0, 15);
}
else
{
r4 = rnd.Next(0, 16);
}
string str_r4 = rBase[r4].Trim();
byte byte1 = Convert.ToByte(str_r1 + str_r2, 16);
byte byte2 = Convert.ToByte(str_r3 + str_r4, 16);
byte[] str_r = new byte[] { byte1, byte2 };
bytes.SetValue(str_r, i);
}
Encoding gb = Encoding.GetEncoding("gb2312");
string[] strArray = new string[bytes.Length];
for (int i = 0; i < bytes.Length; i++)
{
strArray[i] = gb.GetString((byte[])Convert.ChangeType(bytes[i], typeof(byte[])));
}
return strArray;
}
}