List of utility methods to do List Random Item
List | resampleWithReplacement(final List l, final int n) resample With Replacement return resampleWithReplacement(l, n, new Random()); |
E | sample(List sample int i = r.nextInt(l.size()); return l.get(i); |
T | sample(Random random, List sample return list.get(random.nextInt(list.size()));
|
List | sampleRandomSublist(List sample Random Sublist int size = list.size(); if (sampleSize >= size) { List<T> sublist = new ArrayList<T>(list); Collections.shuffle(sublist); return sublist; List<T> sublist = new ArrayList<T>(); Random random = new Random(); ... |
List | sampleWithoutReplacement(List sample Without Replacement if (sampleSize > items.size()) { return items; Random random = new Random(); List<T> sample = new ArrayList<T>(); for (int i = 0; i < sampleSize; i++) sample.add(items.remove(random.nextInt(items.size()))); return sample; ... |
ArrayList | sampleWithReplacement(final Random random, final List extends DataType> data, final int sampleSize) Samples a a given number of items from a list with replacement. final ArrayList<DataType> result = new ArrayList<DataType>(sampleSize); sampleWithReplacementInto(random, data, sampleSize, result); return result; |
void | sampleWithReplacementInto(final Random random, final List extends DataType> data, final int sampleSize, final Collection super DataType> result) Samples a a given number of items from a list with replacement and puts the samples into the given collection. final int dataSize = data.size(); for (int i = 0; i < sampleSize; i++) { final int randomIndex = random.nextInt(dataSize); result.add(data.get(randomIndex)); |
int | softMaxIndex(Random rand, int listSize, double temperature) soft Max Index double rnd = rand.nextDouble(); double total = 0.0d; double[] values = new double[listSize]; int j = listSize + 1; for (int i = 0; i < listSize; i++) { double val = j; j--; values[i] = Math.exp(val / temperature); ... |