Java Code Examples for gnu.trove.list.array.TIntArrayList#removeAt()

The following examples show how to use gnu.trove.list.array.TIntArrayList#removeAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UniversalRandom.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
private int[] sampleWithPrintout(TIntArrayList choices, int[] selectedIndices, List<Integer> collectedRandoms) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.size();
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = nextInt(upperBound);
        //System.out.println("randomIdx: " + randomIdx);
        collectedRandoms.add(randomIdx);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    return selectedIndices;
}
 
Example 2
Source File: UniversalRandom.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique list of the specified sample size of
 * selections from the specified list of choices.
 * 
 * @param choices
 * @param selectedIndices
 * @return an array containing a sampling of the specified choices
 */
public int[] sample(TIntArrayList choices, int[] selectedIndices) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.size();
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = nextInt(upperBound);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    //System.out.println("sample: " + Arrays.toString(selectedIndices));
    return selectedIndices;
}
 
Example 3
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
public static int[] sample(TIntArrayList choices, int[] selectedIndices, Random random) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.size();
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = random.nextInt(upperBound);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    //System.out.println("sample: " + Arrays.toString(selectedIndices));
    return selectedIndices;
}
 
Example 4
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
public static int[] sample(int[] choices, int[] selectedIndices, Random random) {
    TIntArrayList choiceSupply = new TIntArrayList(choices);
    int upperBound = choices.length;
    for (int i = 0; i < selectedIndices.length; i++) {
        int randomIdx = random.nextInt(upperBound);
        selectedIndices[i] = (choiceSupply.removeAt(randomIdx));
        upperBound--;
    }
    Arrays.sort(selectedIndices);
    //System.out.println("sample: " + Arrays.toString(selectedIndices));
    return selectedIndices;
}