lundi 27 novembre 2017

How to produce random symmetric matrix given the number of vertices?

Is there a simple way to produce a random matrix of 0's and 1's, that is symmetric across the diagonal (with only zeros in the diagonal), given the number of vertices?

Example:

somefunction(3) =  [ 0 0 1; 
                     1 0 1; 
                     1 0 0]; 

somefunction(4) = [ 0 1 1 1; 
                    1 0 0 1; 
                    1 0 0 1; 
                    1 1 1 0];




Aucun commentaire:

Enregistrer un commentaire