Group Abstract Group Abstract

Message Boards Message Boards

1
|
4.9K Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Randomize order of elements in two lists

Posted 6 years ago

Hi ,

How do I generate a new list randomly for the list m and then with the same random rule for the list n?

 m={2,1,0,4,8}
 n={13,11,18,27,40}
POSTED BY: Alex Teymouri
5 Replies
Posted 6 years ago

This is equivalent to Rohit's proposal:

m = {2, 1, 0, 4, 8}; n = {13, 11, 18, 27, 40};
perm = Ordering[RandomReal[1, Length[m]]];
m = m[[perm]]; n = n[[perm]];
POSTED BY: J. M.
Posted 6 years ago

Hi Rohit,

Very neat solution.Thank you :)

POSTED BY: Alex Teymouri
Posted 6 years ago

Hi Alex,

Here is another way.

permutation = RandomPermutation[Length@m];
Permute[m, permutation]
Permute[n, permutation]
POSTED BY: Rohit Namjoshi
Posted 6 years ago

Thank you, Hans.

It was a great help:)

POSTED BY: Alex Teymouri

What about this?

<< Combinatorica`


m = {2, 1, 0, 4, 8}
n = {13, 11, 18, 27, 40}
nL = Length[m];
index = Nest[NextPermutation, Range[nL], RandomInteger[nL!]]
mnew = Table[m[[index[[i]]]], {i, nL}]
nnew = Table[n[[index[[i]]]], {i, nL}]
POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard