Need help creating a random generating graph

closed account (GybDjE8b)
So i understand that a graph is N x N matrix so the code i produce below produces a graph, but how do i generate the edges and assign the edges with random weights of 1 - 10. and i need to return (M,L) M = adj matrix, L = adj list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <stdlib.h>

using namespace std;

void gen_random_graph(int n)
{
    int adj_matrix[n][n];
    for(int u = 0; u < n; u++)                         
    {
        for (int v = 0; v < n; v++)             //generating a N x N matrix  based on the # of vertex
        {
            if(adj_matrix[u][v]==adj_matrix[v][u])
            {
                adj_matrix[u][v] = rand() % 10 + 1;
                cout << adj_matrix[u][v] << endl;
            }
        }
    }

}

int main()
{
    int N;
    cout << "Enter number of vertices" << endl;
    cin >> N;
    gen_random_graph(N);

    return 0;
}
Topic archived. No new replies allowed.