You can easily generate all possible combinations of the elements of a list using itertools.combinations
. I am interested in then sampling only a handful of these as efficiently as possible. In some cases, this will mean having millions of combinations and only needing a handful of randomly selected ones.
import itertools
combinations = itertools.combinations(range(1, 30), 10)
I would like to sample e.g. 4 combinations out of all combinations stored in combinations
.
EDIT: previous results can be found here but do not strike me as very efficient.