随机生成不重复的字符串

public static String shuffleForSortingString(String begin ,String end) {
    String uuid = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
    Long randomNum =  System.currentTimeMillis();
    String str = uuid+randomNum;
    char[] c = str.toCharArray();
    List lst = new ArrayList();
    for (int i = 0; i < c.length; i++) {
        lst.add(c[i]);
    }
    //打乱顺序
    Collections.shuffle(lst);

    String resultStr = "";
    for (int i = 0; i < lst.size(); i++) {
        resultStr += lst.get(i);
    }
    return resultStr.substring(begin,end).trim();
}

你可能感兴趣的:(Java基础)