Java Random randomIndices(Random r, int minCount, int maxCount)

Here you can find the source of randomIndices(Random r, int minCount, int maxCount)

Description

random Indices

License

Apache License

Declaration

public static int[] randomIndices(Random r, int minCount, int maxCount) 

Method Source Code

//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;
    }
}

Related

  1. randomGaussian(int numElements)
  2. randomGreyLevels(double max, double min)
  3. randomIcon()
  4. randomID()
  5. randomId()
  6. randomInRange(double min, double max)
  7. randomInsults()
  8. randomIntArray(int len, Random rand)
  9. randomIntegerList(int sz, int min, int max)