生成10到20之间的随机数 int max=20; int min=10; Random random = new Random(); int s = random.nextInt(max)%(max-min+1) + min; System.out.println(s); 生成不一样的随机数 List<Integer> index = new ArrayList<Integer>(); for (int k = 0; k < 10;) { int in = new Random().nextInt(20); if (index.contains(in)) { k = k; System.out.println("重复"); } else { index.add(in); k++; } }