I want to randomize a number of string lists.
The string lists all contain the same number of items, and I wish to apply the same shuffle to each list. So if List1[0] is swapped with List1[7], then I want to swap List2[0] with List2[7], and so on for all the lists.
I’m going to consider the case where you have two lists. I’ll leave it up to you to generalise the ideas to handle more than two lists. The key understanding is best gained using the most simple case where there are two lists.
I would solve the problem like this:
The key is to use the same permutation to shuffle both lists.
And then you can apply to your situation like this:
This is an exceedingly general solution that can be extended to more than two lists, and can be applied to other data types. If you want a very short and simple dedicated routine then you can do it like this:
I’m struggling to think of a good name for this procedure. Can anyone help me out by offering something better?