List of utility methods to do List Random Item
Collection | newRandomStringList(int size, String... strings) Create a Collection containing the given size of the given strings. if (size < 0) { throw new IllegalArgumentException("Size cannot be less than 0. "); if (strings == null || strings.length == 0) { throw new IllegalArgumentException("strings must contains at least one String. "); List<String> list = new ArrayList<String>(size); for (String string : strings) { ... |
String | newRandomV1(int size, int price, List new Random V long start = System.currentTimeMillis(); List<String> randomList = new ArrayList<String>(); int r = 10000000; for (int i = 1; i <= price; i++) { if (!oldRandomList.contains(String.valueOf(r + i))) { randomList.add(String.valueOf(r + i)); long mmmm = System.currentTimeMillis(); long secs = (mmmm - start) / 1000; System.out.println(secs); List<String> ranList = new ArrayList<String>(); for (int j = 0; j < size; j++) { if (randomList.size() > 0) { int ran = new Random().nextInt(randomList.size()); ranList.add((String) randomList.get(ran)); randomList.remove(ran); return ranList.toString().replaceAll("\\s+", "").replace("[", "").replace("]", ""); |
T | nextElement(List Gets a random element from the given list. if (list != null) { int n = list.size(); if (n > 0x00) { return list.get(nextInt(n)); return null; |
T | nextRandomElement(final List Returns the next random element from the given Collection if (list.size() == 0) { throw new RuntimeException("list.size () must be > 0"); final int lowerBound = 0; final int upperBound = list.size(); final int index = lowerBound + random.nextInt(upperBound - lowerBound); return list.get(index); |
List | pickNAtRandom(List pick N At Random if (vals.size() <= n) { return vals; HashSet<T> elems = new HashSet<T>(); Random rand = new Random(seed); for (int i = 0; i < n; i++) { boolean added = true; do { ... |
T | pickOneAtRandom(List pick One At Random return pickOneAtRandom(list, RANDOM);
|
Object | PickRandom(final Collection list) Returns a random object from the list supplied. return PickRandom(list.toArray());
|
LinkedList | pickRandom(LinkedList pick Random if (n <= 0) throw new IllegalArgumentException("Parameter n must be > 0"); if (n > list.size()) return list; int l = list.size(); LinkedList<T> temp = list; LinkedList<T> res = new LinkedList<T>(); Random r = new Random(); ... |
T | pickRandom(List pick Random int index = rnd.nextInt(collection.size()); return collection.get(index); |
String | pickupFromList(String[] list) pickup From List return list[getRandomNumberBelow(list.length)];
|