WOLFRAM

RandomGraph[{n,m}]

gives a pseudorandom graph with n vertices and m edges.

RandomGraph[{n,m},k]

gives a list of k pseudorandom graphs.

RandomGraph[gdist,]

samples from the random graph distribution gdist.

Details and Options

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Generate a random graph on 5 vertices and 6 edges:

Out[1]=1

Simulate a graph property distribution:

Out[1]=1
Out[3]=3

Scope  (12)Survey of the scope of standard use cases

Generate a pseudorandom graph with a given number of vertices and edges:

Out[1]=1

A directed pseudorandom graph:

Out[1]=1

Generate arrays of different sizes and dimensions:

Out[1]=1

An array of graphs:

Out[1]=1

Generate random graphs distributed according to the BarabasiAlbert model:

Out[1]=1

Generate random graphs that are Bernoulli distributed:

Out[1]=1

Generate random graphs that are uniformly distributed:

Out[1]=1

Generate random graphs with given degree sequence:

Out[1]=1

Generate random spatial graphs:

Out[1]=1

Generate random graphs distributed according to the Price model:

Out[1]=1

Generate random graphs distributed according to the WattsStrogatz model:

Out[1]=1

Generate random graphs of large size:

Out[2]=2

Options  (70)Common values & functionality for each option

DirectedEdges  (1)

By default, an undirected graph is generated:

Out[36]=36

Use DirectedEdges->True to generate a directed graph:

Out[35]=35

EdgeLabels  (6)

Label the edge 12:

Out[1]=1

Label all edges:

Out[1]=1
Out[2]=2

Use Placed with symbolic locations to control label placement along an edge:

Out[1]=1

Use explicit coordinates to place labels:

Out[1]=1

Vary positions within the label:

Out[2]=2

Place multiple labels:

Out[1]=1
Out[2]=2

Use automatic labeling by values through Tooltip and StatusArea:

Out[1]=1
Out[2]=2

EdgeShapeFunction  (6)

Get a list of built-in settings for EdgeShapeFunction:

Out[1]=1

Undirected edges including the basic line:

Out[1]=1

Lines with different glyphs on the edges:

Out[2]=2

Directed edges including solid arrows:

Out[1]=1

Line arrows:

Out[2]=2

Open arrows:

Out[3]=3

Specify an edge function for an individual edge:

Out[1]=1

Combine with a different default edge function:

Out[2]=2

Draw edges by running a program:

Out[2]=2

EdgeShapeFunction can be combined with EdgeStyle:

Out[1]=1

EdgeShapeFunction has higher priority than EdgeStyle:

Out[2]=2

EdgeStyle  (2)

Style all edges:

Out[5]=5

Style individual edges:

Out[1]=1

GraphHighlight  (3)

Highlight the vertex 1:

Out[1]=1

Highlight the edge 23:

Out[1]=1

Highlight vertices and edges:

Out[1]=1

GraphHighlightStyle  (2)

Get a list of built-in settings for GraphHighlightStyle:

Out[1]=1

Use built-in settings for GraphHighlightStyle:

Out[1]=1

GraphLayout  (4)

By default, the layout is chosen automatically:

Out[1]=1

Specify layouts on special curves:

Out[1]=1

Specify layouts that satisfy optimality criteria:

Out[1]=1

Use AbsoluteOptions to extract VertexCoordinates computed using a layout algorithm:

Out[1]=1
Out[2]=2

PlotTheme  (4)

Base Themes  (2)

Use a common base theme:

Out[1]=1

Use a monochrome theme:

Out[1]=1

Feature Themes  (2)

Use a large graph theme:

Out[1]=1

Use a classic diagram theme:

Out[1]=1

VertexCoordinates  (3)

By default, any vertex coordinates are computed automatically:

Out[1]=1

Extract the resulting vertex coordinates using AbsoluteOptions:

Out[2]=2

Specify a layout function along an ellipse:

Out[2]=2

Use it to generate vertex coordinates for a graph:

Out[3]=3

VertexCoordinates has higher priority than GraphLayout:

Out[1]=1

VertexLabels  (13)

Use vertex names as labels:

Out[1]=1

Label individual vertices:

Out[1]=1

Label all vertices:

Out[1]=1

Use any expression as a label:

Out[1]=1

Use Placed with symbolic locations to control label placement, including outside positions:

Out[1]=1

Symbolic outside corner positions:

Out[2]=2

Symbolic inside positions:

Out[1]=1

Symbolic inside corner positions:

Out[2]=2

Use explicit coordinates to place the center of labels:

Out[1]=1

Place all labels at the upper-right corner of the vertex and vary the coordinates within the label:

Out[1]=1

Place multiple labels:

Out[1]=1

Any number of labels can be used:

Out[2]=2

Use the argument to Placed to control formatting, including Tooltip:

Out[1]=1

Or StatusArea:

Out[2]=2

Use more elaborate formatting functions:

Out[2]=2
Out[4]=4
Out[6]=6

VertexShape  (5)

Use any Graphics, Image, or Graphics3D as a vertex shape:

Out[1]=1

Specify vertex shapes for individual vertices:

Out[1]=1

VertexShape can be combined with VertexSize:

Out[1]=1

VertexShape is not affected by VertexStyle:

Out[1]=1

VertexShapeFunction has higher priority than VertexShape:

Out[1]=1

VertexShapeFunction  (9)

Get a list of built-in collections for VertexShapeFunction:

Out[1]=1

Use built-in settings for VertexShapeFunction in the "Basic" collection:

Out[1]=1

Simple basic shapes:

Out[2]=2

Common basic shapes:

Out[3]=3

Use built-in settings for VertexShapeFunction in the "Rounded" collection:

Out[1]=1
Out[2]=2

Use built-in settings for VertexShapeFunction in the "Concave" collection:

Out[1]=1
Out[2]=2

Draw individual vertices:

Out[1]=1

Combine with a default vertex function:

Out[2]=2

Draw vertices by running a program:

Out[2]=2

VertexShapeFunction can be combined with VertexStyle:

Out[2]=2

VertexShapeFunction has higher priority than VertexStyle:

Out[4]=4

VertexShapeFunction can be combined with VertexShape:

Out[1]=1

VertexShapeFunction has higher priority than VertexShape:

Out[1]=1

VertexSize  (8)

By default, the size of vertices is computed automatically:

Out[1]=1

Specify the size of all vertices using symbolic vertex size:

Out[1]=1

Use a fraction of the minimum distance between vertex coordinates:

Out[1]=1

Use a fraction of the overall diagonal for all vertex coordinates:

Out[1]=1

Specify size in both the and directions:

Out[1]=1

Specify the size for individual vertices:

Out[1]=1

VertexSize can be combined with VertexShapeFunction:

Out[1]=1

VertexSize can be combined with VertexShape:

Out[1]=1

VertexStyle  (4)

Style all vertices:

Out[1]=1

Style individual vertices:

Out[1]=1

VertexShapeFunction can be combined with VertexStyle:

Out[2]=2

VertexShapeFunction has higher priority than VertexStyle:

Out[4]=4

VertexStyle can be combined with BaseStyle:

Out[1]=1

VertexStyle has higher priority than BaseStyle:

Out[2]=2

Applications  (3)Sample problems that can be solved with this function

Generate random data for a property of a graph distribution and compare its histogram to the PDF:

Out[3]=3

Verify that the degree for a vertex in a Bernoulli graph follows a binomial distribution:

Out[2]=2
Out[3]=3

Simulate interaction networks, knowing the number of interactions of each node within the group:

Out[2]=2

Properties & Relations  (10)Properties of the function, and connections to other functions

RandomGraph uses integer vertices:

Out[1]=1
Out[2]=2

Use VertexReplace to replace vertices in the graph:

Out[3]=3
Out[4]=4

Use SeedRandom to get repeatable random graphs:

Out[1]=1
Out[2]=2

Use BlockRandom to block one use of RandomGraph from affecting others:

Out[1]=1

RandomVariate generates variates from probability distributions:

Out[1]=1

RandomInteger generates uniform discrete random variates:

Out[1]=1

RandomReal generates uniform continuous variates:

Out[1]=1

RandomChoice generates random choices with replacement from a list:

Out[1]=1

RandomSample generates random choice without replacement from a list:

Out[1]=1

RandomPrime generates a random prime number:

Out[1]=1

RandomImage generates a random image:

Out[1]=1

Possible Issues  (1)Common pitfalls and unexpected behavior

The number of edges of a simple graph on n vertices is less than or equal to TemplateBox[{n, 2}, Binomial]:

Out[1]=1

RandomGraph[{n,Binomial[n,2]}] always gives the complete graph with n vertices:

Out[2]=2

Neat Examples  (1)Surprising or curious use cases

Generate random star constellations:

Out[3]=3
Wolfram Research (2010), RandomGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGraph.html.
Wolfram Research (2010), RandomGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGraph.html.

Text

Wolfram Research (2010), RandomGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGraph.html.

Wolfram Research (2010), RandomGraph, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomGraph.html.

CMS

Wolfram Language. 2010. "RandomGraph." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomGraph.html.

Wolfram Language. 2010. "RandomGraph." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomGraph.html.

APA

Wolfram Language. (2010). RandomGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomGraph.html

Wolfram Language. (2010). RandomGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomGraph.html

BibTeX

@misc{reference.wolfram_2025_randomgraph, author="Wolfram Research", title="{RandomGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/RandomGraph.html}", note=[Accessed: 11-May-2025 ]}

@misc{reference.wolfram_2025_randomgraph, author="Wolfram Research", title="{RandomGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/RandomGraph.html}", note=[Accessed: 11-May-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_randomgraph, organization={Wolfram Research}, title={RandomGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/RandomGraph.html}, note=[Accessed: 11-May-2025 ]}

@online{reference.wolfram_2025_randomgraph, organization={Wolfram Research}, title={RandomGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/RandomGraph.html}, note=[Accessed: 11-May-2025 ]}