RandomGraph
✖
RandomGraph
Details and Options

- RandomGraph[{n,m}] is equivalent to RandomGraph[UniformGraphDistribution[n,m]].
- RandomGraph gives a different sequence of pseudorandom graphs whenever you run the Wolfram Language. By using SeedRandom, you can get a repeatable sequence.
- Vertices are taken to be integers 1, …, n.
- A method option to SeedRandom can be given to specify the pseudorandom generator used.
- RandomGraph[dist,{n1,n2,…}] gives an n1×n2×… array of graphs.
- RandomGraph has the same options as Graph.
-
AlignmentPoint Center the default point in the graphic to align with AnnotationRules {} annotations for graph, edges and vertices AspectRatio Automatic ratio of height to width Axes False whether to draw axes AxesLabel None axes labels AxesOrigin Automatic where axes should cross AxesStyle {} style specifications for the axes Background None background color for the plot BaselinePosition Automatic how to align with a surrounding text baseline BaseStyle {} base style specifications for the graphic ContentSelectable Automatic whether to allow contents to be selected CoordinatesToolOptions Automatic detailed behavior of the coordinates tool DirectedEdges Automatic whether to interpret Rule as DirectedEdge EdgeLabels None labels and label placements for edges EdgeLabelStyle Automatic style to use for edge labels EdgeShapeFunction Automatic generate graphic shapes for edges EdgeStyle Automatic style used for edges EdgeWeight Automatic weights for edges Epilog {} primitives rendered after the main plot FormatType TraditionalForm the default format type for text Frame False whether to put a frame around the plot FrameLabel None frame labels FrameStyle {} style specifications for the frame FrameTicks Automatic frame ticks FrameTicksStyle {} style specifications for frame ticks GraphHighlight {} graph elements to highlight GraphHighlightStyle Automatic style for highlight GraphLayout Automatic how to lay out vertices and edges GridLines None grid lines to draw GridLinesStyle {} style specifications for grid lines ImageMargins 0. the margins to leave around the graphic ImagePadding All what extra padding to allow for labels etc. ImageSize Automatic the absolute size at which to render the graphic LabelStyle {} style specifications for labels Method Automatic details of graphics methods to use PerformanceGoal Automatic aspects of performance to try to optimize PlotLabel None an overall label for the plot PlotRange All range of values to include PlotRangeClipping False whether to clip at the plot range PlotRangePadding Automatic how much to pad the range of values PlotRegion Automatic the final display region to be filled PlotTheme $PlotTheme overall theme for the graph PreserveImageOptions Automatic whether to preserve image options when displaying new versions of the same graphic Prolog {} primitives rendered before the main plot RotateLabel True whether to rotate y labels on the frame Ticks Automatic axes ticks TicksStyle {} style specifications for axes ticks VertexCoordinates Automatic coordinates for vertices VertexLabels None labels and placements for vertices VertexLabelStyle Automatic style to use for vertex labels VertexShape Automatic graphic shape for vertices VertexShapeFunction Automatic generate graphic shapes for vertices VertexSize Medium size of vertices VertexStyle Automatic styles for vertices VertexWeight Automatic weights for vertices
List of all options




Examples
open allclose allBasic Examples (2)Summary of the most common use cases
Generate a random graph on 5 vertices and 6 edges:

https://wolfram.com/xid/0tz0t16y-0nrww

Simulate a graph property distribution:

https://wolfram.com/xid/0tz0t16y-swfafb


https://wolfram.com/xid/0tz0t16y-58e9cn

https://wolfram.com/xid/0tz0t16y-6f2lwj

Scope (12)Survey of the scope of standard use cases
Generate a pseudorandom graph with a given number of vertices and edges:

https://wolfram.com/xid/0tz0t16y-5nt9ui

A directed pseudorandom graph:

https://wolfram.com/xid/0tz0t16y-dp8bq9

Generate arrays of different sizes and dimensions:

https://wolfram.com/xid/0tz0t16y-0yua05


https://wolfram.com/xid/0tz0t16y-sxhvuz

Generate random graphs distributed according to the Barabasi–Albert model:

https://wolfram.com/xid/0tz0t16y-2y4h24

Generate random graphs that are Bernoulli distributed:

https://wolfram.com/xid/0tz0t16y-dge2c8

Generate random graphs that are uniformly distributed:

https://wolfram.com/xid/0tz0t16y-wrik2w

Generate random graphs with given degree sequence:

https://wolfram.com/xid/0tz0t16y-1ksz9y

Generate random spatial graphs:

https://wolfram.com/xid/0tz0t16y-63ojdp

Generate random graphs distributed according to the Price model:

https://wolfram.com/xid/0tz0t16y-w5xlp1

Generate random graphs distributed according to the Watts–Strogatz model:

https://wolfram.com/xid/0tz0t16y-wbtk1n

Generate random graphs of large size:

https://wolfram.com/xid/0tz0t16y-cleaem

https://wolfram.com/xid/0tz0t16y-e0j74t

Options (70)Common values & functionality for each option
DirectedEdges (1)
By default, an undirected graph is generated:

https://wolfram.com/xid/0tz0t16y-pprmqz

Use DirectedEdges->True to generate a directed graph:

https://wolfram.com/xid/0tz0t16y-vgbaz2

EdgeLabels (6)

https://wolfram.com/xid/0tz0t16y-z5279


https://wolfram.com/xid/0tz0t16y-1t3zd


https://wolfram.com/xid/0tz0t16y-hr4015

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

https://wolfram.com/xid/0tz0t16y-fnltmw

Use explicit coordinates to place labels:

https://wolfram.com/xid/0tz0t16y-ndfa94

Vary positions within the label:

https://wolfram.com/xid/0tz0t16y-bg84f5


https://wolfram.com/xid/0tz0t16y-33q72


https://wolfram.com/xid/0tz0t16y-hb7fqh

Use automatic labeling by values through Tooltip and StatusArea:

https://wolfram.com/xid/0tz0t16y-dhn5kr


https://wolfram.com/xid/0tz0t16y-bd54a9

EdgeShapeFunction (6)
Get a list of built-in settings for EdgeShapeFunction:

https://wolfram.com/xid/0tz0t16y-hfmhqu

Undirected edges including the basic line:

https://wolfram.com/xid/0tz0t16y-fjhml

Lines with different glyphs on the edges:

https://wolfram.com/xid/0tz0t16y-lxjrsx

Directed edges including solid arrows:

https://wolfram.com/xid/0tz0t16y-lvr0ss


https://wolfram.com/xid/0tz0t16y-qslbt


https://wolfram.com/xid/0tz0t16y-f6ch7m

Specify an edge function for an individual edge:

https://wolfram.com/xid/0tz0t16y-eczrhp

Combine with a different default edge function:

https://wolfram.com/xid/0tz0t16y-jwjk2c

Draw edges by running a program:

https://wolfram.com/xid/0tz0t16y-j0dznf

https://wolfram.com/xid/0tz0t16y-lsgwlp

EdgeShapeFunction can be combined with EdgeStyle:

https://wolfram.com/xid/0tz0t16y-gt52v9

EdgeShapeFunction has higher priority than EdgeStyle:

https://wolfram.com/xid/0tz0t16y-cfn5oz

EdgeStyle (2)
GraphHighlight (3)
GraphHighlightStyle (2)
Get a list of built-in settings for GraphHighlightStyle:

https://wolfram.com/xid/0tz0t16y-lu7p68

Use built-in settings for GraphHighlightStyle:

https://wolfram.com/xid/0tz0t16y-qwjuvn

GraphLayout (4)
By default, the layout is chosen automatically:

https://wolfram.com/xid/0tz0t16y-byozn0

Specify layouts on special curves:

https://wolfram.com/xid/0tz0t16y-cemfdl

Specify layouts that satisfy optimality criteria:

https://wolfram.com/xid/0tz0t16y-0tgqq

Use AbsoluteOptions to extract VertexCoordinates computed using a layout algorithm:

https://wolfram.com/xid/0tz0t16y-gnpepb


https://wolfram.com/xid/0tz0t16y-cp9k9

PlotTheme (4)
Base Themes (2)
VertexCoordinates (3)
By default, any vertex coordinates are computed automatically:

https://wolfram.com/xid/0tz0t16y-5spor

Extract the resulting vertex coordinates using AbsoluteOptions:

https://wolfram.com/xid/0tz0t16y-2whoh

Specify a layout function along an ellipse:

https://wolfram.com/xid/0tz0t16y-mwyuvu

https://wolfram.com/xid/0tz0t16y-cvx31k

Use it to generate vertex coordinates for a graph:

https://wolfram.com/xid/0tz0t16y-uukkr

VertexCoordinates has higher priority than GraphLayout:

https://wolfram.com/xid/0tz0t16y-hdij4u

VertexLabels (13)

https://wolfram.com/xid/0tz0t16y-c9ka50


https://wolfram.com/xid/0tz0t16y-i40mcj


https://wolfram.com/xid/0tz0t16y-whkpg

Use any expression as a label:

https://wolfram.com/xid/0tz0t16y-kokbex

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

https://wolfram.com/xid/0tz0t16y-csc6y

Symbolic outside corner positions:

https://wolfram.com/xid/0tz0t16y-405x2

https://wolfram.com/xid/0tz0t16y-fjgxt8


https://wolfram.com/xid/0tz0t16y-fg0pin

Symbolic inside corner positions:

https://wolfram.com/xid/0tz0t16y-kfrv7

https://wolfram.com/xid/0tz0t16y-dr87wv

Use explicit coordinates to place the center of labels:

https://wolfram.com/xid/0tz0t16y-cqfi4r

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

https://wolfram.com/xid/0tz0t16y-20sv


https://wolfram.com/xid/0tz0t16y-kusfg3

Any number of labels can be used:

https://wolfram.com/xid/0tz0t16y-fqezh

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

https://wolfram.com/xid/0tz0t16y-hg8fi6

Or StatusArea:

https://wolfram.com/xid/0tz0t16y-iyk99o

Use more elaborate formatting functions:

https://wolfram.com/xid/0tz0t16y-bd9m40

https://wolfram.com/xid/0tz0t16y-cggp96


https://wolfram.com/xid/0tz0t16y-l3s7yb

https://wolfram.com/xid/0tz0t16y-cljxny


https://wolfram.com/xid/0tz0t16y-cqkdbb

https://wolfram.com/xid/0tz0t16y-bjoam1

VertexShape (5)
Use any Graphics, Image, or Graphics3D as a vertex shape:

https://wolfram.com/xid/0tz0t16y-dvz661

Specify vertex shapes for individual vertices:

https://wolfram.com/xid/0tz0t16y-i1s9c7

VertexShape can be combined with VertexSize:

https://wolfram.com/xid/0tz0t16y-jqe83v

VertexShape is not affected by VertexStyle:

https://wolfram.com/xid/0tz0t16y-3ef8f

VertexShapeFunction has higher priority than VertexShape:

https://wolfram.com/xid/0tz0t16y-budnxj

VertexShapeFunction (9)
Get a list of built-in collections for VertexShapeFunction:

https://wolfram.com/xid/0tz0t16y-cc7w4d

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

https://wolfram.com/xid/0tz0t16y-kqz1mq


https://wolfram.com/xid/0tz0t16y-hshluc


https://wolfram.com/xid/0tz0t16y-wm2s7

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

https://wolfram.com/xid/0tz0t16y-je3pt2


https://wolfram.com/xid/0tz0t16y-cj5ftp

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

https://wolfram.com/xid/0tz0t16y-f4ea1p


https://wolfram.com/xid/0tz0t16y-bfhgv4


https://wolfram.com/xid/0tz0t16y-fhb0zi

Combine with a default vertex function:

https://wolfram.com/xid/0tz0t16y-fmawhn

Draw vertices by running a program:

https://wolfram.com/xid/0tz0t16y-oroxkx

https://wolfram.com/xid/0tz0t16y-lt54lp

VertexShapeFunction can be combined with VertexStyle:

https://wolfram.com/xid/0tz0t16y-c5uihz

https://wolfram.com/xid/0tz0t16y-djz15m

VertexShapeFunction has higher priority than VertexStyle:

https://wolfram.com/xid/0tz0t16y-h9wrh2

https://wolfram.com/xid/0tz0t16y-ir0ry

VertexShapeFunction can be combined with VertexShape:

https://wolfram.com/xid/0tz0t16y-h6gng4

VertexShapeFunction has higher priority than VertexShape:

https://wolfram.com/xid/0tz0t16y-lnnzsy

VertexSize (8)
By default, the size of vertices is computed automatically:

https://wolfram.com/xid/0tz0t16y-dsy1ve

Specify the size of all vertices using symbolic vertex size:

https://wolfram.com/xid/0tz0t16y-lskxsr

Use a fraction of the minimum distance between vertex coordinates:

https://wolfram.com/xid/0tz0t16y-3lxk1

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

https://wolfram.com/xid/0tz0t16y-my5omo

Specify size in both the and
directions:

https://wolfram.com/xid/0tz0t16y-c7twgs

Specify the size for individual vertices:

https://wolfram.com/xid/0tz0t16y-h6r4ja

VertexSize can be combined with VertexShapeFunction:

https://wolfram.com/xid/0tz0t16y-b3jw4t

VertexSize can be combined with VertexShape:

https://wolfram.com/xid/0tz0t16y-dego1v

VertexStyle (4)

https://wolfram.com/xid/0tz0t16y-ehbi7i


https://wolfram.com/xid/0tz0t16y-dtkst6

VertexShapeFunction can be combined with VertexStyle:

https://wolfram.com/xid/0tz0t16y-om30z

https://wolfram.com/xid/0tz0t16y-nnfnwx

VertexShapeFunction has higher priority than VertexStyle:

https://wolfram.com/xid/0tz0t16y-kfv4n

https://wolfram.com/xid/0tz0t16y-cldcke

VertexStyle can be combined with BaseStyle:

https://wolfram.com/xid/0tz0t16y-bby1h9

VertexStyle has higher priority than BaseStyle:

https://wolfram.com/xid/0tz0t16y-d0df6

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:

https://wolfram.com/xid/0tz0t16y-1hc8ob

https://wolfram.com/xid/0tz0t16y-ps6h8n

https://wolfram.com/xid/0tz0t16y-nebavc

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

https://wolfram.com/xid/0tz0t16y-9cudvl

https://wolfram.com/xid/0tz0t16y-bfveq5


https://wolfram.com/xid/0tz0t16y-k0hqdo

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

https://wolfram.com/xid/0tz0t16y-r2m2lv

https://wolfram.com/xid/0tz0t16y-5rbeo

Properties & Relations (10)Properties of the function, and connections to other functions
RandomGraph uses integer vertices:

https://wolfram.com/xid/0tz0t16y-i79vh


https://wolfram.com/xid/0tz0t16y-ggzae1

Use VertexReplace to replace vertices in the graph:

https://wolfram.com/xid/0tz0t16y-0jtv6


https://wolfram.com/xid/0tz0t16y-l0143m

Use SeedRandom to get repeatable random graphs:

https://wolfram.com/xid/0tz0t16y-udvhjo


https://wolfram.com/xid/0tz0t16y-gg8y8a

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

https://wolfram.com/xid/0tz0t16y-narvr5

RandomVariate generates variates from probability distributions:

https://wolfram.com/xid/0tz0t16y-qdclft

RandomInteger generates uniform discrete random variates:

https://wolfram.com/xid/0tz0t16y-eaw9ak

RandomReal generates uniform continuous variates:

https://wolfram.com/xid/0tz0t16y-bj6cns

RandomChoice generates random choices with replacement from a list:

https://wolfram.com/xid/0tz0t16y-e91k4l

RandomSample generates random choice without replacement from a list:

https://wolfram.com/xid/0tz0t16y-r2y35

RandomPrime generates a random prime number:

https://wolfram.com/xid/0tz0t16y-ebxsg0

RandomImage generates a random image:

https://wolfram.com/xid/0tz0t16y-deuixj

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 :

https://wolfram.com/xid/0tz0t16y-gkktq3


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

https://wolfram.com/xid/0tz0t16y-i471wz

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
]}
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
]}