获取某个区间内不同的随机数
/** * 获取某个区间内n个不同的随机数 * @param min 区间最小值 * @param max 区间最大值(不包含) * @param count 随机数数量 * @return 随机数数组 */ public static int[] getRandom(int min, int max, int count){ int [] indexArray = new int[count]; int indexPosition = 0; Random random = new Random(); indexArray[indexPosition] = random.nextInt((max - min) + 1) + min; indexPosition++; while (indexPosition < count){ boolean isSame = false; int position = random.nextInt((max - min) + 1) + min; for (int i = 0; i < indexPosition; i++){ if (indexArray[i] == position) { isSame = true; break; } } if (!isSame){ indexArray[indexPosition] = position; indexPosition++; } } return indexArray; }