慕哥6287543
废话不多说直接上代码!import java.util.ArrayList;import java.util.Random;public class Test {public static void main(String[] args) {// 生成 [0-n) 个不重复的随机数// list 用来保存这些随机数ArrayList list = new ArrayList();int n = 10;Random rand = new Random();boolean[] bool = new boolean[n];int num = 0;for (int i = 0; i < n; i++) {do {// 如果产生的数相同继续循环num = rand.nextInt(n);} while (bool[num]);bool[num] = true;list.add(num);}System.out.println(list);}}