Java List Random Item getRandomIntBetween(int min, int max, List excludeList)

Here you can find the source of getRandomIntBetween(int min, int max, List excludeList)

Description

get Random Int Between

License

Apache License

Declaration

public static int getRandomIntBetween(int min, int max, List<Integer> excludeList) 

Method Source Code

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

Related

  1. getRandomElement(final List list)
  2. getRandomElement(List myList)
  3. getRandomElementFromList(List l)
  4. getRandomFromList(List list)
  5. getRandomIdxList(int minIdx, int maxIdx)
  6. listChooseOne(List list)
  7. makeListOfIntegersInRange(Integer size, Integer maxOfRange)
  8. makeRandomList(int arraySize, boolean unique)
  9. newRandom(int size, int price, List oldRandomList)