Algorithm to split $n$ distinct items into $k$ nonempty unlabelled subsets
Concretely, let us count the number of ways to partition $[n]$ into $k$ non-empty ordered subsets, which are themselves ordered by increasing order of the first element. For example, a valid partition of 10 into 5 sets is
$$
\{1,4,5\},\{2,3,6\},\{7\},\{8,10\},\{9\}.
$$
Note that $1&lt;2&lt;7&lt;8&lt;9$.

The base cases $k=0,k=1,k=n$ are easy, so suppose $2 \leq k &lt; n$. A partition of $[n]$ into $k$ ordered subsets can be obtained in two ways:


Taking a partition of $[n-1]$ into $k-1$ ordered subsets, and adding a new subset containing only $n$.
Taking a partition of $[n-1]$ into $k$ ordered subsets, and adding $n$ to the 1st subset, the 2nd subset, ..., the $k$th subset.


By recursively generating all partitions of $[n-1]$ into $k-1$ or $k$ ordered subsets, you can thus generate all partitions of $[n]$ into $k$ ordered subsets.

As D.W. mentions, this is just the recurrence for the Stirling numbers.