public static int[] randomize(int[] a, int m) {
        if (a == null || m < 0) return null;
        if (m >= a.length) m = a.length;
        int[] result = Arrays.copyOfRange(a, 0, m);
        for (int i = m; i < a.length; ++i) {
            int r = rand(0, i);
            if (r < m) result[r] = a[i];
        }
        return result;
    }