Here’s a quick and simple way to generate combinations (Knuth):
t = #balls to pick n = #balls in total pos = range(0, t)+[n]+[0] j = 0 while(j < t): j = 0 while(pos[j]+1 == pos[j+1]): pos[j] = j j += 1 pos[j] += 1 f(pos)
I use this for a decoding algorithm to create Hamming balls. It works like a charm.