Page 1 of 1

Java: Adjacency Matrices

Posted: 2005-12-06 08:32am
by Sharp-kun
For a program I'm working on in Java I need to be able to generate a random adjacency matrix for a graph, given only the number of nodes. Funky stuff is then done with this.

Any advice? I've got the rest of the stuff coded and working, its just the random generation thats bugging me.

Posted: 2005-12-06 10:13am
by Durandal
If the matrix is supposed to be unweighted, simply generate a random number and mod it with 2, i.e. matrix[j] = random() % 2;

Posted: 2005-12-06 01:58pm
by Sharp-kun
Got it myself, turned out I just wasn't thinking about it right.