.net产生汉字的类

 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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值