package basic.Lianxi; import java.util.Random; import java.util.Arrays; public class PoolDemo { public static void main(String[] args) { System.out.println(Arrays.toString(gen())); } public static String[] gen() { String pool[] = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33" }; boolean[] used=new boolean[pool.length]; Random r=new Random(); String[] bool=new String[6]; int i=0; while(true){ int index=r.nextInt(pool.length); if(used[index]) continue; bool[i++]=pool[index]; used[index]=true; if(i==bool.length) break; } Arrays.sort(bool); bool=Arrays.copyOf(bool, bool.length+1); bool[bool.length-1]=pool[r.nextInt(16)]; return bool; } }