Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.2K Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Generate new lists with the same order using RandomSample?

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.

POSTED BY: M.A. Ghorbani
4 Replies

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} *)
POSTED BY: Daniel Lichtblau

Dear Daniel,

Your assistance is always appreciated. A great solution!

Mohammad

POSTED BY: M.A. Ghorbani

1 Approach: Use SeedRandom[].

SeedRandom[3];
RandomSample[List1]
SeedRandom[3];
RandomSample[List2]

Regards,

Neil

POSTED BY: Neil Singer

You're the best Neil. Thanks so much.

POSTED BY: M.A. Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard