zoukankan      html  css  js  c++  java
  • 一个随机产生中文简体字的一个类

    static string[] Fonts(int strLength)
    //返回: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;
            }





  • 相关阅读:
    Java 定时任务
    Swing中常用的方法
    瀑布流ajax分页
    权限管理
    图片自动加水印
    jsp自动生成静态页(提供思路)
    分页查询语句
    使用phpmailer发送邮件(以QQ邮箱为例)
    在浏览器的标签页显示网站标志图标(或指定图标)的方法
    随机生成验证码
  • 原文地址:https://www.cnblogs.com/bnjbl/p/954440.html
Copyright © 2011-2022 走看看