Given
elements = Table[Unique["el"], {20}]
{el3, el4, el5, el6, el7, el8, el9, el10, el11, el12, el13, el14, \
el15, el16, el17, el18, el19, el20, el21, el22}
What you want is equivalent to
Partition[RandomSample[elements], 2]
{{el22, el17}, {el12, el6}, {el5, el19}, {el7, el18}, {el9,
el4}, {el13, el21}, {el11, el3}, {el10, el16}, {el14, el15}, {el8,
el20}}
If you want less sets (say 3), you can always do
Partition[RandomSample[elements], 2]~Take~3
{{el4, el18}, {el10, el8}, {el19, el21}}
or more efficiently
Partition[RandomSample[elements, 2 3], 2]
However, if we want to implement your algorithm as you described it (3 times in this example)
Reap[Nest[Complement[#, Sow@RandomSample[#, 2]] &, elements, 3]][[2, 1]]
I'll break this down. Complement[#, Sow@RandomSample[#, 2]] &
. This is a function that takes one argument. The argument should be a list with the remaining elements. It takes 2 random elements of those (RandomSample[#, 2]
) and Sow
s them (puts them aside for later recollection). Then, it returns the original list without those 2 elements.
We apply that function to the whole list of elements, 3 times (Nest[function, elements, 3]
)
Finally, we collect the stuff we put aside in the process (Reap[...][[2, 1]]
)