Generates a random graph.
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
Graph::createRandomGraph(VertexNr
, EdgeNr
, <Directed  Undirected
>)
Graph::createRandomGraph
generates a random
graph.
Graph::createRandomGraph(VertexNr, EdgeNr)
generates
a random graph with VertexNr vertices and EdgeNr edges.
Note: If the number EdgeNr is too great (i.e. ), a complete graph will be created. 
Graph::createRandomGraph(VertexNr, EdgeNr, Undirected)
generates
a random graph with VertexNr vertices and 2 EdgeNr edges
is created. This is due to the fact that no odd number of undirected
edges could be created otherwise.
The following graph was created randomly
,
meaning that your results will most probably differ:
G := Graph::createRandomGraph(5,6): Graph::printGraphInformation(G)
Vertices: [1, 2, 3, 4, 5] Edges: [[1, 4], [2, 1], [2, 4], [2, 5], [3, 1], [3, 4]] Vertex weights: no vertex weights. Edge descriptions: no edge descriptions. Edge weights: no edge weights. Edge costs: no edge costs. Adjacency list (out): 1 = [4], 2 = [1, 4, 5], 3 = [1, 4], 4 = [], 5 = [] Adjacency list (in): 1 = [2, 3], 2 = [], 3 = [], 4 = [1, 2, 3], 5 = [2] Graph is directed.
The same number of vertices, but this time the edges are undirected (and therefore the number of Edges is (2 EdgeNr)). As you can clearly see, the edges differ from the edges created above:
G := Graph::createRandomGraph(5, 6, Undirected): Graph::printGraphInformation(G)
Vertices: [1, 2, 3, 4, 5] Edges: [[1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 2], [4, 1], [4, 2], [4\ , 5], [5, 1], [5, 2], [5, 4]] Vertex weights: no vertex weights. Edge descriptions: no edge descriptions. Edge weights: no edge weights. Edge costs: no edge costs. Adjacency list (out): 1 = [4, 5], 2 = [3, 4, 5], 3 = [2], 4 = [1, 2, 5], 5\ = [1, 2, 4] Adjacency list (in): 1 = [4, 5], 2 = [3, 4, 5], 3 = [2], 4 = [1, 2, 5], 5 \ = [1, 2, 4] Graph is undirected.
If the number of edges to be created extends the possible limit ( ), a complete graph will be returned:
G := Graph::createRandomGraph(3, 6, Undirected): Graph::printGraphInformation(G)
Warning: Cannot produce the required number of edges. Creating a complete graph instead. [Graph::createRandomGraph]
Vertices: [1, 2, 3] Edges: [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]] Vertex weights: no vertex weights. Edge descriptions: no edge descriptions. Edge weights: no edge weights. Edge costs: no edge costs. Adjacency list (out): 1 = [2, 3], 2 = [1, 3], 3 = [1, 2] Adjacency list (in): 1 = [2, 3], 2 = [1, 3], 3 = [1, 2] Graph is undirected.

Positive integer 

Positive integer 

If 

If 
Graph