4
$\begingroup$

If I have a list, I know that I can use the RandomSample function to randomly shuffle the list.

However, if I have $n$ lists, each with the same number of elements, is there a way to randomly shuffle the first list and then make the shuffles of the remaining lists be the same rearrangement?

$\endgroup$

1 Answer 1

6
$\begingroup$

Assuming your lists (let's call them list1 and list2 each have 100 items, then:

order = RandomSample[Range[100]];

list1[[order]] 
list2[[order]]

(see the documentation for Part)

$\endgroup$
2
  • 2
    $\begingroup$ Thank you. Very helpful. I do not think you need curly brackets around order though since it is list already. $\endgroup$
    – Gabi23
    Oct 7, 2021 at 23:59
  • $\begingroup$ Good point @Gabi23—I just typed this blindly. Modified above. $\endgroup$ Oct 8, 2021 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.