@Test public void testRandomSampleViaShuffle() { RandomDataGenerator random = new RandomDataGenerator(new MersenneTwister(123)); List<Integer> arr = Arrays.asList(0, 1, 2, 3, 4); assertEquals(3, RandomUtils.randomSampleViaShuffle(arr, 3, random).size()); assertEquals(5, RandomUtils.randomSampleViaShuffle(arr, 5, random).size()); assertEquals(0, RandomUtils.randomSampleViaShuffle(arr, 0, random).size()); assertEquals(1, RandomUtils.randomSampleViaShuffle(arr, 1, random).size()); }
public static <T> List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random) { List<T> copy = Lists.newArrayList(items); shuffle(copy, sampleSize, random); return copy.subList(0, sampleSize); }
RandomUtils { public static <T> List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random) { List<T> copy = Lists.newArrayList(items); shuffle(copy, sampleSize, random); return copy.subList(0, sampleSize); } }
RandomUtils { public static <T> List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random) { List<T> copy = Lists.newArrayList(items); shuffle(copy, sampleSize, random); return copy.subList(0, sampleSize); }  }
RandomUtils { public static <T> List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random) { List<T> copy = Lists.newArrayList(items); shuffle(copy, sampleSize, random); return copy.subList(0, sampleSize); }  static List<T> sample(List<T> items, int m, RandomDataGenerator random); static List<T> sampleMore(List<T> items, int m, RandomDataGenerator random); static List<T> sample(List<T> items, int m, Set<T> forbidden, RandomDataGenerator random); static List<T> sampleWithReplacement(List<T> items, int m, RandomDataGenerator random); static int[] shuffleInts(int[] ar, RandomDataGenerator random); static List<T> shuffle(List<T> items, RandomDataGenerator random); static List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random); static int nextInt(int lower, int upper, RandomDataGenerator random); static double nextUniform(double lower, double upper, RandomDataGenerator random); static T pickRandom(List<T> items, RandomDataGenerator random); static int pickRandom(int[] arr, RandomDataGenerator random); static T pickRandom(T[] arr, RandomDataGenerator random); static double[] randomDoubleVector(int n, double minValue, double maxValue, RandomDataGenerator random); static float[] nextFloatVector(int n, float minValue, float maxValue, RandomDataGenerator random); static int sampleAccordingToDistribution(RandomDataGenerator random, double[] probabilities); }
RandomUtils { public static <T> List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random) { List<T> copy = Lists.newArrayList(items); shuffle(copy, sampleSize, random); return copy.subList(0, sampleSize); }  static List<T> sample(List<T> items, int m, RandomDataGenerator random); static List<T> sampleMore(List<T> items, int m, RandomDataGenerator random); static List<T> sample(List<T> items, int m, Set<T> forbidden, RandomDataGenerator random); static List<T> sampleWithReplacement(List<T> items, int m, RandomDataGenerator random); static int[] shuffleInts(int[] ar, RandomDataGenerator random); static List<T> shuffle(List<T> items, RandomDataGenerator random); static List<T> randomSampleViaShuffle(Iterable<T> items, int sampleSize, RandomDataGenerator random); static int nextInt(int lower, int upper, RandomDataGenerator random); static double nextUniform(double lower, double upper, RandomDataGenerator random); static T pickRandom(List<T> items, RandomDataGenerator random); static int pickRandom(int[] arr, RandomDataGenerator random); static T pickRandom(T[] arr, RandomDataGenerator random); static double[] randomDoubleVector(int n, double minValue, double maxValue, RandomDataGenerator random); static float[] nextFloatVector(int n, float minValue, float maxValue, RandomDataGenerator random); static int sampleAccordingToDistribution(RandomDataGenerator random, double[] probabilities);  }