@Test public void testSampleMore() { RandomDataGenerator random = new RandomDataGenerator(new MersenneTwister(123)); List<Integer> arr = Arrays.asList(0, 1); List<Integer> integers = RandomUtils.sampleMore(arr, 41, random); int cnt0 = 0, cnt1 = 0; for (Integer i : integers) { cnt0 += (i == 0 ? 1 : 0); cnt1 += (i == 1 ? 1 : 0); } Assert.assertEquals(1, Math.abs(cnt0 - cnt1)); }
public static <T> List<T> sampleMore(List<T> items, int m, RandomDataGenerator random) { final List<T> res = new ArrayList<>(m); int remainder = m; while (remainder >= items.size()) { res.addAll(items); remainder -= items.size(); } res.addAll(sample(items, remainder, random)); RandomUtils.shuffle(res, random); return res; }
RandomUtils { public static <T> List<T> sampleMore(List<T> items, int m, RandomDataGenerator random) { final List<T> res = new ArrayList<>(m); int remainder = m; while (remainder >= items.size()) { res.addAll(items); remainder -= items.size(); } res.addAll(sample(items, remainder, random)); RandomUtils.shuffle(res, random); return res; } }
RandomUtils { public static <T> List<T> sampleMore(List<T> items, int m, RandomDataGenerator random) { final List<T> res = new ArrayList<>(m); int remainder = m; while (remainder >= items.size()) { res.addAll(items); remainder -= items.size(); } res.addAll(sample(items, remainder, random)); RandomUtils.shuffle(res, random); return res; }  }
RandomUtils { public static <T> List<T> sampleMore(List<T> items, int m, RandomDataGenerator random) { final List<T> res = new ArrayList<>(m); int remainder = m; while (remainder >= items.size()) { res.addAll(items); remainder -= items.size(); } res.addAll(sample(items, remainder, random)); RandomUtils.shuffle(res, random); return res; }  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> sampleMore(List<T> items, int m, RandomDataGenerator random) { final List<T> res = new ArrayList<>(m); int remainder = m; while (remainder >= items.size()) { res.addAll(items); remainder -= items.size(); } res.addAll(sample(items, remainder, random)); RandomUtils.shuffle(res, random); return res; }  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);  }