Here you can find the source of getRandomIntBetween(int min, int max, List
public static int getRandomIntBetween(int min, int max, List<Integer> excludeList)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static int getRandomIntBetween(int min, int max, List<Integer> excludeList) { int value = getRandomInt(max, false); while (value < min || excludeList.contains(value)) { value = getRandomInt(max, false); }/*from w w w . jav a 2 s . c o m*/ return value; } public static int getRandomInt(int max, boolean excludeMax) { if (excludeMax) { return ((int) (Math.random() * max)); } else { return (int) Math.round((Math.random() * max)); } } public static int getRandomInt(int max, List<Integer> excludeList, boolean excludeMax) { int value = getRandomInt(max, excludeMax); while (excludeList.contains(value)) { value = getRandomInt(max, excludeMax); } return value; } }