<commit_before>package org.broadinstitute.sting.utils;

import java.util.List;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Random;

/**
 * Created by IntelliJ IDEA.
 * User: andrew
 * Date: Jul 2, 2009
 * Time: 3:12:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class ListUtils {

    static Random rand = new Random(12321); //System.currentTimeMillis());

    static public ArrayList<Integer> sampleIndicesWithReplacement(int n, int k) {
        // Returns n random indices drawn with replacement from the range 1..k

        ArrayList<Integer> chosen_balls = new ArrayList <Integer>();
        for (int i=0; i<n; i++) {
            //Integer chosen_ball = balls[rand.nextInt(k)];
            chosen_balls.add(rand.nextInt(k));
            //balls.remove(chosen_ball);
        }

        return chosen_balls;
    }

    static public <T> ArrayList<T> sliceListByIndices(List<Integer> indices, List<T> list) {
        // Given a list of indices into a list, return those elements of the list with the possibility
        // of drawing list elements multiple times

        ArrayList<T> subset = new ArrayList<T>();

        for (int i : indices) {
            subset.add(list.get(i));
        }
        
        return subset;
    }


}<commit_msg>Added ability to sample from a list *without* replacement.<commit_after>package org.broadinstitute.sting.utils;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: andrew
 * Date: Jul 2, 2009
 * Time: 3:12:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class ListUtils {

    static Random rand = new Random(12321); //System.currentTimeMillis());

    /**
     * Returns n random indices drawn with replacement from the range 0..(k-1)
     *
     * @param n  the number of random indices to draw (with replacement)
     * @param k  the total number of indices allowed
     * @return a list of random indices ranging from 0 to (k-1) with possible duplicates
     */
    static public ArrayList<Integer> sampleIndicesWithReplacement(int n, int k) {

        ArrayList<Integer> chosen_balls = new ArrayList <Integer>();
        for (int i=0; i<n; i++) {
            //Integer chosen_ball = balls[rand.nextInt(k)];
            chosen_balls.add(rand.nextInt(k));
            //balls.remove(chosen_ball);
        }

        return chosen_balls;
    }

    /**
     * Returns n random indices drawn without replacement from the range 0..(k-1)
     *
     * @param n  the number of random indices to draw (without replacement)
     * @param k  the total number of indices allowed
     * @return a list of random indices ranging from 0 to (k-1) without duplicates
     */
    static public ArrayList<Integer> sampleIndicesWithoutReplacement(int n, int k) {
        ArrayList<Integer> chosen_balls = new ArrayList<Integer>(k);

        for (int i = 0; i < n; i++) {
            chosen_balls.add(i);
        }

        Collections.shuffle(chosen_balls, rand);

        //return (ArrayList<Integer>) chosen_balls.subList(0, k);
        return new ArrayList<Integer>(chosen_balls.subList(0, k));
    }

    /**
     * Given a list of indices into a list, return those elements of the list with the possibility of drawing list elements multiple times

     * @param indices  the list of indices for elements to extract
     * @param list     the list from which the elements should be extracted
     * @param <T>      the template type of the ArrayList
     * @return         a new ArrayList consisting of the elements at the specified indices
     */
    static public <T> ArrayList<T> sliceListByIndices(List<Integer> indices, List<T> list) {
        ArrayList<T> subset = new ArrayList<T>();

        for (int i : indices) {
            subset.add(list.get(i));
        }
        
        return subset;
    }


}
{'fraction_non_alphanumeric': 0.10077720207253886, 'fraction_numerical': 0.011398963730569948, 'mean_word_length': 2.584958217270195, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5624608', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1065, 'n_words': 384}