zoukankan      html  css  js  c++  java
  • 自动生成 中文随机名字(转)

    发现一个 很好用的 随机名字 代码,于是稍微改一改,能直接用在u3d上。当然 还是要感谢 作者,和哥当初 思考的方式一样,那些小白说 随机一些内置的中文 真傻缺了

    using UnityEngine;
    using System.Collections;
    using System.Text;
    public class GenerateChineseWords
    { 
        /// <summary>
        /// 随机产生常用汉字
        /// </summary>
        /// <param name="count">要产生汉字的个数</param>
        /// <returns>常用汉字</returns>
        public static string GenerateChineseWord(int count)
        {
            string chineseWords = "";
            System.Random rm = new System.Random();
            Encoding gb = Encoding.GetEncoding("gb2312");
    
            for (int i = 0; i < count; i++)
            {
                // 获取区码(常用汉字的区码范围为16-55)
                int regionCode = rm.Next(16, 56);
    
                // 获取位码(位码范围为1-94 由于55区的90,91,92,93,94为空,故将其排除)
                int positionCode;
                if (regionCode == 55)
                {
                    // 55区排除90,91,92,93,94
                    positionCode = rm.Next(1, 90);
                }
                else
                {
                    positionCode = rm.Next(1, 95);
                }
    
                // 转换区位码为机内码
                int regionCode_Machine = regionCode + 160;// 160即为十六进制的20H+80H=A0H
                int positionCode_Machine = positionCode + 160;// 160即为十六进制的20H+80H=A0H
    
                // 转换为汉字
                byte[] bytes = new byte[] { (byte)regionCode_Machine, (byte)positionCode_Machine };
                chineseWords += gb.GetString(bytes);
            }
            return chineseWords;
        }
    }
  • 相关阅读:
    Poj 3713 Transferring Sylla 3-连通
    SPOJ 7758 Growing Strings AC自动机DP
    ural 1209. 1,10,100,1000.....
    ural 1197. Lonesome Knight
    ural 1149. Sinus Dances
    优先级队列
    Codeforces Round #384 (Div. 2) C. Vladik and fractions
    Codeforces Round #384 (Div. 2) B. Chloe and the sequence
    Codeforces Round #384 (Div. 2) A. Vladik and flights
    POJ 1246 Find The Multiple
  • 原文地址:https://www.cnblogs.com/big-zhou/p/5136316.html
Copyright © 2011-2022 走看看