List of utility methods to do List Random Item
T | getRandomElement(List Get a random element from a list. return myList.get(getRandomOffset(myList.size()));
|
T | getRandomElementFromList(List get Random Element From List return l.get((int) (Math.random() * l.size())); |
T | getRandomFromList(List get Random From List int position = (int) (Math.random() * (list.size() - 1)); return list.get(position); |
List | getRandomIdxList(int minIdx, int maxIdx) get Random Idx List List<Integer> randomIdxList = new ArrayList<Integer>(); for (int i = minIdx; i <= maxIdx; i++) randomIdxList.add(i); return randomIdxList; |
int | getRandomIntBetween(int min, int max, List get Random Int Between int value = getRandomInt(max, false); while (value < min || excludeList.contains(value)) { value = getRandomInt(max, false); return value; |
T | listChooseOne(List list Choose One if (list.size() == 1) { return list.get(0); if (list.size() > 1) { return list.get(R.nextInt(list.size())); return null; |
List | makeListOfIntegersInRange(Integer size, Integer maxOfRange) make List Of Integers In Range List<Integer> returnVal = new ArrayList<>(); Random random = new Random(27350); while (returnVal.size() < size) { Integer currentVal = random.nextInt(maxOfRange); if (!returnVal.contains(currentVal)) { returnVal.add(currentVal); return returnVal; |
ArrayList | makeRandomList(int arraySize, boolean unique) make Random List int[] values = makeRandomArray(arraySize, unique); ArrayList<Integer> result = new ArrayList<Integer>(); for (int i = 0; i < values.length; i++) { result.add(values[i]); return result; |
String | newRandom(int size, int price, List new Random if (size > 500) { return newRandomV2(size, price, oldRandomList); Map<String, Integer> randomMap = new HashMap<String, Integer>(); int r = 10000000; for (int i = 1; i <= price; i++) { randomMap.put(String.valueOf(r + i), new Integer(0)); for (int i = 0; i < oldRandomList.size(); i++) { randomMap.put(oldRandomList.get(i), new Integer(1)); List<String> ranList = new ArrayList<String>(); for (int j = 0; j < size; j++) { if (randomMap.size() > 0) { int range = randomMap.size() - oldRandomList.size() - j; if (range < 1) { range = 1; int ran = new Random().nextInt(range); int max = Math.min(ran + oldRandomList.size() + size, randomMap.size()); String[] keys = new String[randomMap.size()]; randomMap.keySet().toArray(keys); for (int k = 0, x = 0; k < max; k++) { String key = keys[k]; Integer flag = randomMap.get(key); if (flag == 0) { if (x == ran) { ranList.add(key); randomMap.put(key, new Integer(1)); break; x++; return ranList.toString().replaceAll("\\s+", "").replace("[", "").replace("]", ""); |
Collection | newRandomIntegerList(int size) Create a collection containing the given number of random integers. if (size < 0) { throw new IllegalArgumentException("Size cannot be less than 0. "); Collection<Integer> integers = new ArrayList<Integer>(size); for (int i = 0; i < size; i++) { integers.add(RANDOM.nextInt()); return integers; ... |