I've done a bit of Googling with hopes of finding an answer, but to no avail. I'm looking for a way that I can have Mathematica take the elements of a list, say {a,b,c,d}
, and partition the elements into lists of length 2 but allowing the grouping of these elements to be random. The Partition
function nearly produces the desired results, but groups the elements in {a,b,c,d}
in the order they appear (i.e. the result is {{a,b},{c,d}}
) when I would like a random pairing such as {{a,d},{c,b}}
.
Is there some way of utilizing the Partition
function so that it allows me achieve this? Or there perhaps another built-in function or combination of built-in functions that do this?
Thank you all so very much.
Partition[RandomSample[(* stuff *)], (* stuff *)]
ought to work… $\endgroup${a,b,c,d}
, but when using this with the list I'm working with that is of length 19, it gives me the error "RandomSample cannot generate a random sample of length 2 which is greater than the length of the sample set". UPDATE: I got it to work! Thank you! $\endgroup$ConvertedList
and initially used the following inputPartition[RandomSample[{ConvertedList}],5],2]
which resulted in an error because the curly brackets weren't necessary. WritingPartition[RandomSample[ConvertedList],5],2]
fixed the issue. $\endgroup$