水池抽样, reservoir sample
static int[] randomPick(int[] array, int k) {
int[] res = new int[k];
Random r = new Random();
for (int i = 0; i < k; i++) {
res[i] = array[i];
}
for (int i = k; i < array.length; i++) {
int index = r.nextInt(i);
if (index < k) {
res[index] = array[i];
}
}
return res;
}