### Question:
RandomSampler { public List<T> sample(List<T> data, int sampleNumber) { if (data == null) { throw new IllegalArgumentException("Input list is null"); } if (data.size() < sampleNumber) { return data; } List<T> result = new ArrayList<T>(sampleNumber); int n = data.size(); for (int i = 0; i < n; i++) { if (i < sampleNumber) { result.add(data.get(i)); } else { int j = rdm.nextInt(i); if (j < sampleNumber) { result.set(j, data.get(i)); } } } return result; }  List<T> sample(List<T> data, int sampleNumber);  }### Answer:
@Test public void test() { RandomSampler<Text> s = new RandomSampler<Text>(); List<Text> data = new ArrayList<Text>(); for (int i = 0; i < 1000; i++) { data.add(new Text(String.valueOf(i))); } List<Text> result = s.sample(data, 50); System.out.println(result); assertEquals(50, result.size()); }
@Test public void test() { RandomSampler<String> s = new RandomSampler<String>(); List<String> data = new ArrayList<String>(); for (int i = 0; i < 1000; i++) { data.add(String.valueOf(i)); } List<String> result = s.sample(data, 50); System.out.println(result); assertEquals(50, result.size()); }