private static void subset0(
		final RandomGenerator random,
		final int n,
		final int k,
		final int[] a
	) {
		assert k <= a.length;
		assert k <= n - k;

		// Early return if k = 1.
		if (k == 1) {
			a[0] = random.nextInt(n);
			return;
		}

		// (A): Initialize a[i] to "zero" point for bin Ri.
		for (int i = 0; i < k; ++i) {
			a[i] = (i*n)/k;
		}

		// (B)
		int l, x;
		for (int c = 0; c < k; ++c) {
			do {
				// Choose random x;
				x = 1 + random.nextInt(n);

				// determine range Rl;
				l = (x*k - 1)/n;
			} while (a[l] >= x); // accept or reject.

			++a[l];
		}
		int s = k;

		// (C) Move a[i] of nonempty bins to the left.
		int m = 0, p = 0;
		for (int i = 0; i < k; ++i) {
			if (a[i] == (i*n)/k) {
				a[i] = 0;
			} else {
				++p;
				m = a[i];
				a[i] = 0;
				a[p - 1] = m;
			}
		}

		// (D) Determine l, set up space for Bl.
		for (; p > 0; --p) {
			l = 1 + (a[p - 1]*k - 1)/n;
			final int ds = a[p - 1] - ((l - 1)*n)/k;
			a[p - 1] = 0;
			a[s - 1] = l;
			s -= ds;
		}

		// (E) If a[l] != 0, a new bin is to be processed.
		int r = 0, m0 = 0;
		for (int ll = 1; ll <= k; ++ll) {
			l = k + 1 - ll;

			if (a[l - 1] != 0) {
				r = l;
				m0 = 1 + ((a[l - 1] - 1)*n)/k;
				m = (a[l - 1]*n)/k - m0 + 1;
			}

			// (F) Choose a random x.
			x = m0 + random.nextInt(m);
			int i = l + 1;

			// (G) Check x against previously entered elements in bin;
			//     increment x as it jumps over elements <= x.
			while (i <= r && x >= a[i - 1]) {
				++x;
				a[i - 2] = a[i - 1];
				++i;
			}

			a[i - 2] = x;
			--m;
		}

		// Convert to zero-based indexed arrays.
		for (int i = 0; i < k; ++i) {
			--a[i];
		}
	}
Selects a random subset of size {@code k} from a set of size {@code n}.

@param n the size of the set.
@param k the size of the subset.
@param rnd the random number generator used.
@throws NullPointerException if {@code random} is {@code null}.
@throws IllegalArgumentException if {@code n < k}, {@code k == 0} or if
        {@code n*k} will cause an integer overflow.
@return the a-set array for the given parameter. The returned subset
        array is sorted in increasing order.
jenetics/src/main/java/io/jenetics/internal/math/Subsets.java