C#⾃动⽣成中⽂随机名字
using UnityEngine;//From:www.uzhanbao
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);
param name}
return chineseWords;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。