/** * Gets a list of integers(size specified by the given size) between the * specified start(inclusion) and end(inclusion) randomly. * * @param start the specified start * @param end the specified end * @param size the given size * @return a list of integers */ public static List<Integer> getRandomIntegers(final int start, final int end, final int size) { if (size > (end - start + 1)) { throw new IllegalArgumentException("The specified size more then (end - start + 1)!"); } final List<Integer> integers = genIntegers(start, end); final List<Integer> ret = new ArrayList<Integer>(); int remainsSize; int index; while (ret.size() < size) { remainsSize = integers.size(); index = (int) (Math.random() * (remainsSize - 1)); final Integer i = integers.get(index); ret.add(i); integers.remove(i); } return ret; }
/** * Gets a list of integers(size specified by the given size) between the * specified start(inclusion) and end(inclusion) randomly. * * @param start the specified start * @param end the specified end * @param size the given size * @return a list of integers */ public static List<Integer> getRandomIntegers(final int start, final int end, final int size) { if (size > (end - start + 1)) { throw new IllegalArgumentException("The specified size more then (end - start + 1)!"); } final List<Integer> integers = genIntegers(start, end); final List<Integer> ret = new ArrayList<Integer>(); int remainsSize; int index; while (ret.size() < size) { remainsSize = integers.size(); index = (int) (Math.random() * (remainsSize - 1)); final Integer i = integers.get(index); ret.add(i); integers.remove(i); } return ret; }