其他分享
首页 > 其他分享> > 随机生成不重复的字符串

随机生成不重复的字符串

作者:互联网

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<Character> lst = new ArrayList<Character>();
    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();
}

标签:begin,end,resultStr,重复,int,lst,随机,字符串,String
来源: https://blog.csdn.net/wjc2013481273/article/details/100729009