我认为比较高效的 取出四个不同的 随机数
public static void main(String[] args) { HashSet<Integer> hs = new HashSet<Integer>(); Random rand = new Random(); int randInt = 0; while(hs.size()<4){ randInt = rand.nextInt(100); hs.add(randInt); } System.out.println(hs.toString()); }