package com.goafanti.common.utils; import java.util.Random; public class RandomUtil { public static int[]generateRandomList(int maxNum,int count){ int[] res=new int[count]; Random rand = new Random();//新建一个随机类 boolean[] bool = new boolean[maxNum]; int randInt = 0; for(int i = 0; i < count ; i++) { do { randInt = rand.nextInt(maxNum);//产生一个随机数 }while(bool[randInt]); bool[randInt] = true; System.out.println(randInt); res[i]=randInt; } return res; } }