Skip to content
Advertisement

Choose at random from combinations

I can make a list of all combinations using list(itertools.combinations(range(n), m)) but this will typically be very large.

Given n and m, how can I choose a combination uniformly at random without first constructing a massive list??

Advertisement

Answer

From http://docs.python.org/2/library/itertools.html#recipes

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement