Java: Adjacency Matrices

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
Sharp-kun
Sith Devotee
Posts: 2993
Joined: 2003-09-10 05:12am
Location: Glasgow, Scotland

Java: Adjacency Matrices

Post 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.
User avatar
Durandal
Bile-Driven Hate Machine
Posts: 17927
Joined: 2002-07-03 06:26pm
Location: Silicon Valley, CA
Contact:

Post 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;
Damien Sorresso

"Ever see what them computa bitchez do to numbas? It ain't natural. Numbas ain't supposed to be code, they supposed to quantify shit."
- The Onion
User avatar
Sharp-kun
Sith Devotee
Posts: 2993
Joined: 2003-09-10 05:12am
Location: Glasgow, Scotland

Post by Sharp-kun »

Got it myself, turned out I just wasn't thinking about it right.
Post Reply