Generating a random directed graph I wrote a function that returns a directed graph as an adjacency matrix. The function requires two arguments: the amount of nodes and the amount of edges. At first, nodes are placed and instantly connected to the graph. When all nodes are added, random edges are created until all edges are placed.
Code:
public int[,] GenerateMatrix(int Nodes, int Edges)
    {
        if (Edges &lt; Nodes - 1) throw new Exception(&quot;Too few edges&quot;);
        if (Edges &gt; Nodes * (Nodes - 1)) throw new Exception(&quot;Too many edges&quot;);

        int[,] adjacencyMatrix = new int[Nodes, Nodes];

        // Gives every cell a value of zero
        for (int y = 0; y &lt; Nodes; y++)
        {
            for (int x = 0; x &lt; Nodes; x++)
            {
                adjacencyMatrix[x, y] = 0;
            }
        }

        int placedEdges = 0;

        for (int i = 1; i &lt; Nodes; i++)
        {
            // produce edge between rnd(0, amountofnodes) to new node
            int fromVertex = random.Next(0, i);
            int weight = random.Next(1, 10);

            adjacencyMatrix[i, fromVertex] = weight;
            placedEdges++;
        }

        while (placedEdges &lt; Edges)
        {
            int fromVertex = random.Next(0, Nodes);
            int weight = random.Next(1, 10);

            int targetVertex = random.Next(0, Nodes);
            while (targetVertex == fromVertex || adjacencyMatrix[targetVertex, fromVertex] != 0) //|| adjacencyMatrix[fromVertex, targetVertex] != 0)// tredje condition tar bort parallella kanter
            {
                fromVertex = random.Next(0, Nodes);
                targetVertex = random.Next(0, Nodes);
            }

            adjacencyMatrix[targetVertex, fromVertex] = weight;
            placedEdges++;
        }

        return adjacencyMatrix;
    }
Here are my suggestions:

Nodes, Edges: most of the time the function's parameters don't start with big letter. nodes and edges are more preferable.

Also consider to restraint the possible range of these variables. uint or even smaller like ushort might be a better fit for your use case.


throw new Exception: It is good that you do preliminary checks. Usually the preferred Exception type is ArgumentException (1) to indicate that you have a problem with the calling parameters.

adjacencyMatrix: You don't need to zero all of the entries inside this matrix because by default their value will be zero. (int is a value type with a default value 0).

If you wish to clean the array, because you have received that for example via a parameter then you can use the built-in Array.Clear (1):
Array.Clear(adjacencyMatrix, 0, adjacencyMatrix.Length);


random.Next(0, i): Alternative: random.Next() % i 

random.Next(1, 10): Alternative: new Random().Next() * (10 - 1) + 1 (1) 

placedEdges++: instead of increasing it every time you could initialize it with the proper value: int placedEdges = Nodes -1;

fromVertex and targetVertex:

fromVertex + toVertex
OR sourceVertex and targetVertex would

give more convenient naming.