Here you can find the source of randomIndices(Random r, int minCount, int maxCount)
public static int[] randomIndices(Random r, int minCount, int maxCount)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static int[] randomIndices(Random r, int minCount, int maxCount) { minCount = Math.max(Math.min(minCount, maxCount), 1); maxCount = Math.max(minCount, maxCount); List<Integer> tmp = new ArrayList<>(maxCount); for (int i = 0; i < maxCount; i++) { tmp.add(i);//from w w w. jav a 2 s .com } Collections.shuffle(tmp); final int outputCount = minCount + r.nextInt(maxCount - minCount); int[] output = new int[outputCount]; for (int i = 0; i < outputCount; i++) { output[i] = tmp.get(i); } return output; } }