Ant-soldier

main方法中使用:

//随机生成100个汉字

String ss="";
for(int i=0;i<100;i++){
ss+=getChinese(i);
}
System.out.println(ss);

结果如图:

//随机生成汉字
//seed指定Random(long seed)中的种子数
public static String getChinese(long seed)
throws UnsupportedEncodingException
{
String str=null;
int highpos,lowpos;
Random random=new Random(seed);
highpos=(176+Math.abs(random.nextInt(39)));
lowpos=(161+Math.abs(random.nextInt(93)));
byte[] bb=new byte[2];
bb[0]=new Integer(highpos).byteValue();
bb[1]=new Integer(lowpos).byteValue();
//String(byte[] bytes, Charset charset)
//通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String。
str=new String(bb,"GBK");
return str;
}

这里有个关于讲解汉字区位码以及GB2312的背景知识,感兴趣的可以参考一下,里面有个利用c#程序编写的汉字生成器.

链接:http://www.cnblogs.com/skyivben/archive/2012/10/20/2732484.html

分类:

技术点:

相关文章:

  • 2022-01-30
  • 2021-12-13
  • 2021-12-24
  • 2022-12-23
  • 2021-12-15
  • 2021-11-30
猜你喜欢
  • 2021-04-30
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
相关资源
相似解决方案