I'm trying to create a For loop (Using the For syntax is a necessity for the future work I'd be performing) for a matrix given by the following lines of code:
m1 = SparseArray[_ :> RandomInteger[1], {10, 10}];
SM = UpperTriangularize[m1] + Transpose[UpperTriangularize[m1, 1]];
MatrixForm[SM]
The matrix given above is a symmetric matrix given by 0's and 1's only. I need a For loop which would do the following: A random [i,j] element is picked and is converted from either 1 -> 0 or from 0 ->1. So for example, in my 10 x 10 matrix, if [1,5] is randomly chosen, if the value started as a 1, the loop would change it to a 0. Conversely, if that value started as a 0, the loop would change it to a 1. Additionally, due to wanting to maintain the symmetry, for every [i,j] element picked, I need the corresponding [j,i] value changed as well. Lastly, each iteration needs to be building off the previous iteration. I want to be able to simulate this an infinite number of times and see how the matrix changes over performing the loop multiple times.
As mentioned above, it's a necessity that a For loop is used (even though it's sort of advised against due to other methods being more worthwhile).
For
in Mathematica. If you disagree, give a counterexample. $\endgroup$