Stepping back from the following question :
I need to generate a random Set (1 000 000 items would be enough)
Subsets[Flatten[ParallelTable[{i, j}, {i, 1, 96}, {j, 1, 4}], 1], {4}]
Further, I need to reject any quadruples with non-unique first elements, such as {{1,1},{1,2},{2,3},{6,1}}.
But the above is impossible on a laptop. How could I just draw uniformly one millions sets avoiding killing my machine ?
Provided you have a base set you need to generate 4-element subsets of,
you can use
RandomSampleas follows:This gives you a length-4 random subset of
baseSet. Generating a million of them takes 2.5 seconds on my very old machine:Not all of what we get are going to be different subsets, so we need to remove duplicates using
Union:After this I’m still left with 999 971 items in a sample run, thanks to the much larger number of possible subsets (
Binomial[Length[baseSet], 4] == 891 881 376)