random Chinese - Java Internationalization

Java examples for Internationalization:Chinese

Description

random Chinese

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {

    public static String randomChinese() throws Exception {
        String str = null;/*from  www.  j av a  2  s .c  om*/
        int hightPos, lowPos; 
        Random random = new Random();
        hightPos = (176 + Math.abs(random.nextInt(39)));
        lowPos = (161 + Math.abs(random.nextInt(93)));
        byte[] b = new byte[2];
        b[0] = (new Integer(hightPos).byteValue());
        b[1] = (new Integer(lowPos).byteValue());
        str = new String(b, "GBk");
        return str;
    }

    public static String randomChinese(int count) {
        String str = "";
        for (int i = 0; i < count; i++) {
            try {
                str += randomChinese();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return str;
    }
}

Related Tutorials