Java Utililty Methods List Random Item

List of utility methods to do List Random Item

Description

The list of methods to do List Random Item are organized into topic(s).

Method

ListresampleWithReplacement(final List l, final int n)
resample With Replacement
return resampleWithReplacement(l, n, new Random());
Esample(List l, Random r)
sample
int i = r.nextInt(l.size());
return l.get(i);
Tsample(Random random, List list)
sample
return list.get(random.nextInt(list.size()));
ListsampleRandomSublist(List list, int sampleSize)
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();
...
ListsampleWithoutReplacement(List items, int sampleSize)
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;
...
ArrayListsampleWithReplacement(final Random random, final List 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;
voidsampleWithReplacementInto(final Random random, final List data, final int sampleSize, final Collection 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));
intsoftMaxIndex(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);
...