Random rand = new Random(47); Set<Integer> set = new HashSet<Integer>(); for(int i=0;i<10000;i++){ set.add(rand.nextInt(30)); System.out.println(set); }
//输出
/*
[8]
[5, 8]
[5, 8, 13]
[5, 8, 11, 13]
[1, 5, 8, 11, 13]
[1, 5, 8, 11, 13, 29]
[1, 5, 8, 11, 28, 13, 29]
[1, 20, 5, 8, 11, 28, 13, 29]
[1, 20, 5, 8, 11, 28, 12, 13, 29]
[1, 20, 5, 7, 8, 11, 28, 12, 13, 29]
[1, 18, 20, 5, 7, 8, 11, 28, 12, 13, 29]
[1, 18, 20, 5, 7, 8, 11, 28, 12, 13, 29]
*/
2.应用