Here you can find the source of generateInteger(int min, int maxInclusive, List
public static Integer generateInteger(int min, int maxInclusive, List<Integer> excludedValues)
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Random; public class Main { public static Integer generateInteger(int min, int maxInclusive) { Random rand = new Random(); return rand.nextInt((maxInclusive - min) + 1) + min; }/*www.j a v a 2s .c o m*/ public static Integer generateInteger(int min, int maxInclusive, List<Integer> excludedValues) { int random = generateInteger(min, maxInclusive); boolean found = false; for (Integer val : excludedValues) { if (val == random) { found = true; } } if (found) { return generateInteger(min, maxInclusive, excludedValues); } else { return random; } } }