ghorbani
(MA Ghorbani)
1
Hi
I have two lists as below :
List1 = {a1, b1, c1, d1}
List2 = {a2, b2, c2, d2}
with using RandomSample[ ] how I can generate new lists with the same order for both lists. For example :
RandomSample[List1]
{b1, d1, a1, c1}
RandomSample[List2]
{b2, d2, a2, c2}
Many thanks for your help.
neils
(Neil Singer)
2
1 Approach: Use SeedRandom[].
SeedRandom[3];
RandomSample[List1]
SeedRandom[3];
RandomSample[List2]
Regards,
Neil
ghorbani
(MA Ghorbani)
3
You’re the best Neil.
Thanks so much.
danl
(Daniel Lichtblau)
4
RandomSample can be emulated by creating a random reordering of the integers 1,2,…length(list). Then just use the same reordering on both lists.
list1 = {a1, b1, c1, d1};
list2 = {a2, b2, c2, d2};
randOrder = RandomSample[Range[Length[list1]]]
list1[[randOrder]]
list2[[randOrder]]
(* Out[679]= {2, 3, 4, 1}
Out[680]= {b1, c1, d1, a1}
Out[681]= {b2, c2, d2, a2} *)
ghorbani
(MA Ghorbani)
5
Dear Daniel,
Your assistance is always appreciated. A great solution!
Mohammad