package quant.rich.emoney.util;

import java.util.Random;

public class TextUtils {

    private static final Random random = new Random();

    /**
     * 提供 n 位的 A-Za-z0-9 的随机字串
     * 
     * @param n
     * @return
     */
    public static String randomString(int n) {
        return randomString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", n);
    }
    
    public static String randomString(String from, int n) {
        StringBuilder sb = new StringBuilder(n);
        for (int i = 0; i < n; i++) {
            sb.append(from.charAt(random.nextInt(from.length())));
        }
        return sb.toString();
    }

}
