RandomStringUtils.java 689 Bytes
package com.example.utils;

import java.util.UUID;

/**
 * RandomStringUtils
 * <p/>
 * Created by caobug on 15/6/23.
 */
public class RandomStringUtils extends org.apache.commons.lang3.RandomStringUtils {

    public static final String ARTICLE_KEY_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String getString() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 根据字母表生成指定位数随机字符串
     *
     * @param length 随机长度
     * @return 随机字符串
     */
    public static String getString(int length) {
        return random(length, ARTICLE_KEY_ALPHABET);
    }
}