Java List Random Item generateInteger(int min, int maxInclusive, List excludedValues)

Here you can find the source of generateInteger(int min, int maxInclusive, List excludedValues)

Description

generate Integer

License

Open Source License

Declaration

public static Integer generateInteger(int min, int maxInclusive, List<Integer> excludedValues) 

Method Source Code


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

    }
}

Related

  1. choose(Random random, List list)
  2. chooseRandom(List list)
  3. chooseRandomElement(List list, Random random)
  4. computeCrossProduct(List> allArgPossibilities, int maximumSize)
  5. findFirst(List list, T value, Comparator comparator)
  6. getRandomElement(final List list)
  7. getRandomElement(List myList)
  8. getRandomElementFromList(List l)
  9. getRandomFromList(List list)