Here you can find the source of randomCommon(int min, int max, int n)
public static int[] randomCommon(int min, int max, int n)
//package com.java2s; public class Main { public static int[] randomCommon(int min, int max, int n) { if (max == min + n) { return null; }/*from w w w. ja v a2 s . c o m*/ if (n > (max - min + 1) || max < min) { return null; } int[] result = new int[n]; int count = 0; while (count < n) { int num = (int) (Math.random() * (max - min)) + min; boolean flag = true; for (int j = 0; j < n; j++) { if (num == result[j]) { flag = false; break; } } if (flag) { result[count] = num; count++; } } return result; } }