I need to generate random combinations (unordered tuples without duplication). This code works fine for relatively small $n$ but I need much larger n $n>200$ for example
n:=20; # fails for n=200
enum:=EnumeratorOfCombinations([1..n]);
for k in [1..10] do
b:=enum[Random([1..2^n])];
Print(b,"\n");
od;
# result :
[ 1, 2, 3, 5, 9, 11, 14, 15, 17, 18, 20 ]
[ 1, 5, 6, 7, 9, 11, 12, 14, 17, 18 ]
[ 2, 4, 5, 6, 10, 13, 14, 18, 19 ]
[ 2, 7, 9, 10, 11, 12, 14, 17, 18 ]
[ 3, 9, 10, 11, 13, 14, 15, 17, 18 ]
[ 3, 5, 7, 8, 9, 11, 14, 17, 18, 19, 20 ]
[ 1, 2, 3, 6, 7, 10, 15, 16, 19 ]
[ 1, 2, 4, 7, 8, 10, 12, 13, 17, 19, 20 ]
[ 1, 2, 3, 7, 8, 13, 14, 17 ]
[ 2, 3, 4, 6, 8, 16, 17, 18, 19 ]
Are there other options for doing this in GAP?
Do you really want to produce random combinations of any size (instead of some fixed size)? So, if for example $n=3$, you want to pick uniformly at random from the 8 combinations [], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]? That's an incredibly convoluted way of saying you want to pick a random subset of the $n$ elements, with all $2^n$ subsets equally probable. I'm sure you can find easier ways of doing that. (For each of the $n$ elements, you just want to include it in the subset with probability $0.5$.)
That having been said, your interesting solution does almost work. For large $n$ it fails because Random([1..2^n]) tries to build a Range with a huge upper limit:
You can instead call a version of Random that does not require a range. Just give it the lower and upper limits as integers.