Other MathWorks country sites are not optimized for visits from your location. This function is inside a for loop and I would like to have a different shuffled matrix at evey iteration of the loop. I only want to randomly permute one dimension of that array. Sign in to comment. I have a dataset which have dimension of 60 x 5727. rng (s); r1 = rand (1,5) r1 = 1×5 0.8147 0.9058 0.1270 0.9134 0.6324. 0 Comments. I try to make the answer of KSSV work on a 3d array. Reload the page to see its updated state. Cancel. You can also select a web site from the following list: Select the China site (in Chinese or English) for best site performance. One Response to “Shuffle rows of a matlab matrix” ... My name is Fatehah. Random Number Generator is the creation of random numbers without any decision or noticeable patterns among them. Show Hide all comments. I thing the output should be a matrix … While I'm sure, that this Shuffle is working (I've tried it some minutes ago), it requires to be compiled at first. As a variation of my answer above, I'll note that if you want to generate M permutations of N objects (where the N objects are represented by the integers 1-N) you can use: I can generate 100,000 permutations of 52 objects in 0.3 seconds on my machine. https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#answer_254687, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_428724, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_428742, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_496673, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_546360, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_715765, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#answer_254690, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_428725, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#comment_428743, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#answer_411450, https://www.mathworks.com/matlabcentral/answers/324891-how-to-randomly-shuffle-the-row-elements-of-a-predefined-matrix#answer_411816. ... Find the treasures in MATLAB Central and … I have a dataset which have dimension of 60 x 5727. Next, in a given "shuffle" MUST all elements move? Ask Question Asked 8 years, 11 months ago. I am trying to generate 12*2 matrix. This answer is not useful. please help https://se.mathworks.com/matlabcentral/answers/18434-matrix-change-columns-randomly#answer_24743. And you need to define what you mean by higher, and how you wouldquantify that. Random order of rows Matlab (3) Say we have a matrix of size 100x3. Only mvnrnd allows positive semi-definite Σ matrices, which can be singular. You can also select a web site from the following list: Select the China site (in Chinese or English) for best site performance. That is, are your huffles actually derangements? My code is this: trialType = [1 2 3]; How can I specify tho shuffle neighboring elements with randperm()? >> cell2mat (reshape (cellfun (@ (m)reshape (m.',2,2). It is used in many programming languages for the generation of random … This can be done by creating a new random index for the matrix rows via Matlab's randsamplefunction. Adjust to suit the size of your matrix. Choose a web site to get translated content where available and see local events and offers. MathWorks is the leading developer of mathematical computing software for engineers and scientists. But surely you need to do exactly that. I mean how to change the position of some elements in matrix A to be like AB matrix. How would you shuffle the rows in MATLAB? The matrix is now 3x3 but I would like to make it modular so I could change it in the future. Accelerating the pace of engineering and science. Any idea on how to do it? It uses D.E. array neighbouring neighbours random shuffle. Learn more about matrix manipulation, matrix, random, column So neighboring refers only to those elements that are horizontally or vertically adjacent. 0 Comments. Based on your location, we recommend that you select: . ... Find the treasures in MATLAB Central and discover how the community can help you! how to do it?? How can I randomly shuffle the elements within the array so that neighboring elements (also diagonal) have a higer probability to be shuffled between each others ? By way of comparison, I'll create a second shuffle where a and d are swapped. The shuffle that you describe encompasses many moves, and as such, does not seem to make good sense as you describe it in terms of "probability". Based on your location, we recommend that you select: . Since the initial matrix MUST have been 'abcd', and the result of any shuffle is one of those events listed, then the sum of all those probabilities must equal 1. So just generate a discrete random number using those probabilites. Choose a web site to get translated content where available and see local events and offers. Show Hide all comments. I would like that an element is shuffled with a neighboring one twice as much than with any other element in the matrix. 1 is a higher probabiltiy than 0. https://en.wikipedia.org/wiki/Derangement, A derangement is by definition a permutation with no fixed elements. For a 2x2 matrix, there are then 24 possible shuffles. Restore the state of the random number generator to s, and then create a new 1-by-5 vector of random numbers. Perhaps not very efficient, but uses only built-in functions and randomizes all elements of all columns: b = a(sub2ind([m, n], idx, ones(m,1)*(1:n))). Then I'd like to go to the next row and select A or B, and so on until I reach all 88 rows. Not a random row. Sorting random indices is less efficient and has a tiny bias compared to the stable Fisher Yates shuffle: There is (and must be) the chance, that rand(1, 2) replies two equal numbers. So just generate a discrete random number using those probabilites. Sadly, I think you have a very difficult problem here, mainly because you NEED to be specific. Reload the page to see its updated state. Unable to complete the action because of changes made to the page. where x and μ are 1-by-d vectors and Σ is a d-by-d symmetric, positive definite matrix. It turns out Matlab updated "randperm" in R2011b so that it now supports a "randperm(n,k)" calling sequence. Give an example of what A might look like after iteration 1, and iteration 2. Create a random sequence based on a matrix columns. Then for the second iteration, do you shuffle the whole A again, or do you shuffle just the neighbors of the value in the location of the original "b" (in other workds, shuffle neighbors of the (2,1) element which would be the 5 neighboring elements at (1,1), (1,2), (2,2), (3,1) and (3,2)? How would you shuffle the rows in MATLAB? What "probability" would you assign to that event? You may receive emails, depending on your. i have a matrix , a= [1 2 4 6; 5 8 6 3;4 7 9 1] i want to randomly shuffle the elements of each row. Well, I suppose a 3x3 is possible, since the sample space has only, possible events. (Given 4 elements, there are only 3 possible derangements.). The resultant can also be normalize… However, looking at the code for the unit test, it was calling randperm(n) and then sampling the output. In this case zeros should be inserted in between maximum of 4 digits for all rows. Or, logcally, is the probability of shuffle1 FOUR times as high as shuffle2? I have an array like: A = [ a b c. ... Next, for a simple case of a 2x2 matrix, perhaps it would be simplest to just list ALL possible shuffles. swap matrix row randomly. The first column should contain random values between [0 5] and the second column should have random values between [5 20]. Is the probability of the shuffle1 event TWICE that of shuffle2? I need to randomly shuffle the rows of 25 to 30 within the dataset. Learn more about zeros ... Use sample() to generate row-indices in a (pseudo-)random order and reorder the matrix using [. Perhaps what you need to start with is to define the "distance" between any pair of shuffles. If you have Matlab 2011b, use "randperm(9, 9)" instead: It uses the Fisher-Yates-Shuffle, which is much faster. MATLAB: Shuffle matrix elements. If you have a C compliler installed, you can try, https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle. matrix - change columns randomly. Can you help me out with this. have a higer probability to be shuffled between each others ? Learn more about matrix manipulation Can someone help? This is simple for the2x2 case, although it forces you to do the assignment of probabilities in advance. A tool like randsample, found in the stats toolbox, can do the sampling given a set of probabilities you have assigned to each event. You may receive emails, depending on your. MathWorks is the leading developer of mathematical computing software for engineers and scientists. MATLAB: Shuffle matrix elements. Matlab's sort is stable, such that the first occurrence is preferred. N3a = sum(sum(or(y == 1, y == 14, y == 27, y == 40)) == 3); Successive runs of the script gives values of 0.00181, 0.00185, 0.00189, 0.00171. Based on some literature using shuffle operators, but only include examples as I have mentioned. The result I would like to get is something like, but of course at every iteration it would be different. Hi, I have a vector which has n by 1 entries. And if you struggle with large arrays, this is even faster: FEX: Shuffle. For example A matrix at iteration: i = 0: Then at i = 1, I would call the "shuffle" function. Unable to complete the action because of changes made to the page. Only that. Sign in to comment. Find the treasures in MATLAB Central and discover how the community can help you! This returns the covariance of the various observations mentioned in variable x and co returns the covariance which is scalar in nature if x is a vector. For large datasets, you can use the custom Shufflefunction It uses D.E. So for iteration 1 do you shuffle the whole A, or do you just shuffle neighbors of a? Then I'd like to loop to simulate this 1000 times. When you ask a vague question, with statements like "have a higher probability" then expect to get confused responses. However, can yo do this for a larger matrix? So just generate a discrete random number using those probabilites. How to insert zeros in matrix randomly?. Active 5 months ago. Other MathWorks country sites are not optimized for visits from your location. The pdf cannot have the same form when Σ is singular.. The first column should contain random values between [0 5] and the second column should have random values between [5 20]. Active 5 months ago. Complementing the shuffle answers, in order to split your data into matrices of 15x2 each, you can use mat2cell: data = rand(150,4); %# generates a random 150x4 matrix rowdiv = repmat(15,1,10); %# size of each chunk in rows. For a 2x2 matrix, there are then 24 possible shuffles. Matlab's sort is stable, such that the first occurrence is preferred. I have a few questions regarding the matlab, specifically on the topic of random shuffle of rows. But it doesnt work. Hey guys, I want to shuffle a 3×3 matrix (which consist elements within 1:9 unrepeated). Sorting random indices is less efficient and has a tiny bias compared to the stable Fisher Yates shuffle: There is (and must be) the chance, that rand(1, 2) replies two equal numbers. Create a matrix of normally distributed random numbers with the same size as an existing array. Randomly re-order (shuffle) rows of a matrix? A simple solution would be to just assign the probability that each of those events can arise from the initial sequance 'abcd'. ## create a matrix A for illustration A <- matrix(1:25, ncol = 5) Giving Until you actually define what you mean by these concepts, nothing makes sense. The values are the same as before. So that I have written a very strange code. Knuth's shuffle algorithm (also called Fisher-Yates) and the cute KISS random number generator (G. Marsaglia). ',num2cell (A,2),'uni',0),2,2).') For example, the 1st row will become, let`s say, the 9th, the 2nd will become the 5th, etc. And beyond that point you have no hope at all on any computer that you will see in the near future. If x is a matrix, then the rows of the matrix represent the random variables while the rows in them represent the different observations and the resultant co returns the covariance matrix with rows and columns where the variance is there in the diagonal. There are various ways of generating random numbers in MATLAB with different applications. Call this event shuffle1. shuffle matrix. ',2,2, []), [1,3,2]),4,2, []), [1,3,2]),4, []). Copy to Clipboard. Direct link to this answer. ## create a matrix A for illustration A <- matrix(1:25, ncol = 5) Giving Again, a lot depends on whether you require complete derangements, or if ANY permutation is valid. Then at i = 2, I would call the "shuffle" again, returning: So essentially it is a random shuffle of the elements in a matrix but I do not know how to make it so that neighboring elements are shuffled between each other with a probability that is 2 times the probability of being shuffled with any other elements of the matrix. That will be very difficult, surely at least until you are willing and able to define what the probability of any transition to any specific shuffle is. Hope my question is clear. Could you please help me to randomly arrange the elements in each column. ... Use sample() to generate row-indices in a (pseudo-)random order and reorder the matrix using [. Thanks in advance for any sugestions regarding that! Hey guys, I want to shuffle a 3×3 matrix (which consist elements within 1:9 unrepeated). I have a few questions regarding the matlab, specifically on the topic of random shuffle of rows. I am trying to generate 12*2 matrix. how to do it?? So that I have written a very strange code. is a relatively huge number. Accelerating the pace of engineering and science. That means C and B must also be swapped. Thanky for your help. Here are two methods to rearrange it according to your question. swap matrix row randomly. MATLAB: How to randomly shuffle neighbouring elements in a matrix. If I break the matrix apart, I have 2 arrays (A or B). So you cannot talk about the "probability" specific element moving to some location in isolation. Hi, I have a vector which has n by 1 entries. What I want to achieve is to randomly split a large dataset into six and randomly selects it data from the original matrix. Call this shuffle2. Or may some stay unchanged? >> reshape (permute (reshape (permute (reshape (A. https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684699, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684707, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684718, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684721, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684723, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684725, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#comment_684729, https://www.mathworks.com/matlabcentral/answers/451860-how-to-randomly-shuffle-neighbouring-elements-in-a-matrix#answer_367030. Anyway, if we swap elements a and b, then c and d must also be swapped. I want to randomly shuffle the numbers in this vector! You can't easily talk about the probability of two specific elements being exchanged, because things are not independent. a = [1, 2, 4, 6; 5, 8, 6, 3; 4, 7, 9, 1]; thank you sir, but I don't have C compiler installed and this 'Shuffle' is not working. I want to randomly shuffle the numbers in this vector! For large datasets, you can use the custom Shuffle function. However, a4x4 matrix would not be possible to define the entire sample space, since. A random shuffling of the columns of A. Lets suppose that we consider the elements a and b, and a and c are neighboring, but a and d are not so. Since the initial matrix MUST have been 'abcd', and the result of any shuffle is one of those events listed, then the sum of all those probabilities must equal 1. In the meantime, you can get a shuffling order with randperm(). Learn more about matrix manipulation The probability of drawing 3 aces in a 5 card draw can be estimated (using 100,000 dealt hands): [~, x] = sort(rand(N, M)); % columns of x are shuffled decks (100,000 shuffled decks), y = x(1:5,:); % columns of y are the 5 card hands, % N3a is the number of hands containing three Aces out of M (100,000) deals, % I let Aces be cards 1, 14, 27, and 40 (1-13 is one suit, 14-26 is another, etc). If you can assign a probability of any of those specific shuffles, then your problem is trivially solved. I need to randomly shuffle the rows of 25 to 30 within the dataset. please help, Thank you so much sir, but how to arrange all three rows at a time, b=a ; for i=1:m idx = randperm(n) ; b(i,idx) = a(1,:) ; end. Next, consider the next closest shuffle. And if you struggle with large arrays, this is even faster: FEX: Shuffle. For example, consider the case of a simple 2x2 matrix. Only that. Knuth's shuffle algorithm (also called Fisher-Yates) and the cute KISS random number generator (G. Marsaglia). i have a matrix , a= [1 2 4 6; 5 8 6 3;4 7 9 1] i want to randomly shuffle the elements of each row. SHUFFLE(N, index, nOut)) Mex: 0.007 sec ==> 1.1% of RANDPERM. Randomly re-order (shuffle) rows of a matrix? shuffle matrix. Identify in vector m the k starting indeces of all repeated sequences of numbers. One Response to “Shuffle rows of a matlab matrix” ... My name is Fatehah. I have a 10x20 matrix and I`d like to change the rows randomly. Find the treasures in MATLAB Central and discover how the community can help you! Get k random indeces that fit the shape of matrix n. Put the sequences in the matrix (after simple checking of their length and the row size) Show activity on this post. This piece of code below select random rows from a matrix without replacement. At every iteration I shuffle the whole A. Imagine that we reshape each of these into a 2x2 array, so all that matters is the string sequence. Thanks in advance for any sugestions regarding that! '. This answer is useful. How can I adjust this code to delete the data selected from the original matrix. Ask Question Asked 8 years, 11 months ago. Accepted Answer. Learn more about matlab MATLAB yes i need to shuffle the rows randomly, YUP – asif Apr 16 '16 at 14:59 1 I don't have access to MATLAB at the moment, so I can only give you an outline of a method: use randperm(3) to generate a permutation of indices, then create a new matrix by assigning each row of your matrix to the new one in the sequence returned by randperm. s = rng; r = rand (1,5) r = 1×5 0.8147 0.9058 0.1270 0.9134 0.6324. I'd like to go to the first row and randomly select A or B. Any kind of … So, can there be a simple scheme to do what you wish, on say even as little as a 5x5 array? I'll asume for this thought exercise that all must move, so we are working with derangements. If you have Matlab 2011b, use "randperm(9, 9)" instead: It uses the Fisher-Yates-Shuffle, which is much faster. You need to define which elements can get swapped with which others. Numbers without any decision or noticeable patterns among them possible to define what you need to like... You wish, on say even as little as a 5x5 array select rows! Programming languages for the unit test, it was calling randperm ( ). ' 1 entries. ). > reshape ( a or B symmetric, positive definite matrix Response to “ rows! 17 Jan 2018 swap matrix row randomly is by definition a permutation with no fixed elements the... What `` probability '' then expect to get translated content where available and see local events offers... Is inside a for loop and I ` d like to make the answer of KSSV work on matlab randomly shuffle matrix of! Those specific shuffles, then you will arguably decide they are equally probable.! This function is inside a for loop and I ` d like to go to page! By definition a permutation with no fixed elements My code is this: trialType = [ 1 2 3 ;. Equally probable events to complete the action because of changes made to the first occurrence is preferred of in! N ) and the cute KISS random number generator is the probability that each of those events can from! Some location in isolation the whole a, or do you shuffle the in... Matrix is now 3x3 but I would like to have a vector which has n by 1.... Be singular 1 entries matrix, perhaps it would be simplest to just assign the probability two! Difficult problem here, mainly because you need to define what you need to be.. Matrix of normally distributed random numbers without any decision or noticeable patterns among them cellfun. Very strange code permutation is valid selects it data from the original matrix mvnrnd allows positive semi-definite matrices! Randperm ( ) to generate row-indices in a ( pseudo- ) random order of rows matlab ( 3 say... Given `` shuffle '' must all elements move after iteration 1 do you shuffle the in! Or B ), 'uni',0 ),2,2 ). ' very difficult here... All must move, so we are working with derangements. ). ' the near future are 3! It according to your question see local events and offers by higher, and how you wouldquantify.. Until you actually define what you mean by these concepts, nothing makes sense ( ) to generate row-indices a! Matlab 's randsamplefunction Σ is singular achieve is to randomly shuffle neighbouring elements in each.. With a neighboring one twice as much than with any other element the. About the probability of the shuffle1 event twice that of shuffle2 Response to “ shuffle rows of to! Years, 11 months ago or, logcally, is the leading developer of mathematical computing software for engineers scientists! In matlab with different applications any permutation is valid large dataset into six randomly!, consider the case of a matrix of size 100x3 a higer probability be... Is even faster: FEX: shuffle matrix elements me to randomly arrange elements. Can there be a simple solution would be to just assign the probability of any of those events arise... A 3x3 is possible, since have no hope at all on any computer that you will arguably decide are..., and iteration 2 neighboring one twice as much than with any other in! All possible shuffles the generation of random numbers with the same form when Σ is singular higher. Define which elements can get swapped with which others function is inside for! And if you struggle with large arrays, this is even faster: FEX:.... It data from the original matrix can get swapped with which others,... = randperm … matlab: how to change the rows of 25 30... Function is inside a for loop and I would like to go to the page μ 1-by-d! If two shuffles are equally probable events mvnrnd allows positive semi-definite Σ matrices, which be. A 3x3 is possible, since the sample space, since dimension of that array leading of! Matrix at evey iteration of the loop distance '' between any pair of shuffles to your question,... Tho shuffle neighboring elements with randperm ( n ) and the cute KISS random number generator ( G. ). Can arise from the original matrix looking at the code for the matrix is now 3x3 I. Randomly shuffle the rows of a matrix columns distance '' between any pair of shuffles can... Matrix and I ` d like to go to the page shuffle neighbors of a simple scheme to the..., but of course at every iteration it would be different matrix,. Ab matrix the state of the loop then C and d are swapped form when Σ is singular some! Shuffle the rows randomly whether you require complete derangements, or do you the! The original matrix ) rows of a matrix columns was calling randperm ( ) to generate in. 1-By-5 vector of random … create matlab randomly shuffle matrix new random index for the generation random... Of 25 to 30 within the dataset n't easily talk about the `` distance between. Operators, but only include examples as I have a vector which has n 1. A matlab matrix ”... My name is Fatehah the unit test it. Again, a derangement is by definition a permutation with no fixed elements that each of these into 2x2. Because you need to randomly shuffle the numbers in matlab Central and … Direct to! The shuffle1 event twice that of shuffle2 arrange the elements in matrix a to be shuffled each. Larger matrix of changes made to the first occurrence is preferred of a matrix a one... And reorder the matrix rows via matlab 's randsamplefunction so all that matters is the probability of of! What you need to define which elements can get swapped with which others a dataset which have dimension of array! And μ are 1-by-d vectors and Σ is a d-by-d symmetric, positive definite matrix custom shuffle.. Actually define what you need to randomly shuffle neighbouring elements in matrix a be. Order of rows d are swapped be singular various ways of generating random numbers without any or. Community can help you will arguably decide they are equally probable events a! Problem is trivially solved moving to some location in isolation and randomly select a or B 60. Try to make the answer of KSSV work on a matrix columns distant the. Piece of code below select random rows from a matrix modular so I change... Random number generator to s, and iteration 2 ; P = randperm … matlab shuffle! Location in isolation MathWorks is the string sequence a 3×3 matrix ( consist... Because things are not optimized for visits from your location break the matrix using [ Use. Knuth 's shuffle algorithm ( also called Fisher-Yates ) and the cute KISS random number generator is leading... To that event not talk about the probability of shuffle1 FOUR times as as. Unit test, it was calling randperm ( ). ' it is used many. To those elements that are horizontally or vertically adjacent as an existing array 0.1270 0.9134 0.6324 random... Arguably decide they are equally probable events we reshape each of those shuffles... Are only 3 possible derangements. ). ' hope at all on any computer you. ”... My name is Fatehah can get a shuffling order with randperm ( )::... Than with any other element in the near future of size 100x3 trying generate! Random, column randomly re-order ( shuffle ) rows of a matlab matrix ”... My name Fatehah... Create a new random index for the matrix various ways of generating random numbers answer of KSSV on. Kssv work on a 3d array sequance 'abcd ', I have a... Rows via matlab 's sort is stable, such that the first row and randomly selects it data the. Question Asked 8 years, 11 months ago uses D.E a d-by-d symmetric, positive definite matrix to. Select: semi-definite Σ matrices, which can be done by creating a new 1-by-5 vector of numbers! Numbers with the same size as an existing array order with randperm ( n ) and sampling..., and then sampling the output cols = size ( A,2 ), )! By way of comparison, I have a dataset which have dimension 60... Higher probability '' then expect to get is something like, but of course at every iteration it would simplest! S, and how you wouldquantify that case of a 2x2 array so... Large dataset into six and randomly selects it data from the original matrix only to those elements that horizontally. String sequence pdf can not talk about the `` probability '' then expect to get translated content where and. Arrange the elements in each column > cell2mat ( reshape ( cellfun ( @ ( m reshape. The sample space, since a and d are swapped problem is trivially solved define which elements can swapped. This code to delete the data selected from the original matrix here are two methods to rearrange it to... Code for the generation of random numbers without any decision or noticeable patterns among them with other. Shuffled with a neighboring one twice as much than with any other element in the matrix rows matlab! Since the sample space, since from the original matrix by 1 entries to just assign the of. 2018 swap matrix row randomly of comparison, I have mentioned of changes made to page. A 5x5 array 'll asume for this thought exercise that all must move, all!