RandomGraph[{n,m}]
n 個の頂点と m 本の辺を持つ擬似ランダムグラフを返す.
RandomGraph[{n,m},k]
k 個の擬似ランダムグラフのリストを返す.
RandomGraph[gdist,…]
ランダムグラフ分布 gdist からのサンプルを返す.
RandomGraph
グラフ分布のリスト »RandomGraph[{n,m}]
n 個の頂点と m 本の辺を持つ擬似ランダムグラフを返す.
RandomGraph[{n,m},k]
k 個の擬似ランダムグラフのリストを返す.
RandomGraph[gdist,…]
ランダムグラフ分布 gdist からのサンプルを返す.
詳細とオプション
- RandomGraph[{n,m}]はRandomGraph[UniformGraphDistribution[n,m]]に等しい.
- RandomGraphは,Wolfram言語を実行するたびに擬似ランダムグラフの異なる数列を返す.SeedRandomを使うと繰返し可能な数列が得られる.
- 頂点は整数 1, …, n であるとみなされる.
- SeedRandomのメソッドオプションで,使用する擬似乱数ジェネレータが指定できる.
- RandomGraph[dist,{n1,n2,…}]はグラフの n1×n2×…配列を返す.
- RandomGraphにはGraphと同じオプションが使える.
全オプションのリスト
例題
すべて開く すべて閉じる例 (2)
RandomGraph[{5, 6}]RandomGraph[BernoulliGraphDistribution[6, 0.4]]data = EdgeCount /@ RandomGraph[BernoulliGraphDistribution[6, 0.4], 10 ^ 3];Show[Histogram[data, Automatic, "PDF"],
DiscretePlot[PDF[BinomialDistribution[15, 0.4], m], {m, 0, 15}, Joined -> True]]スコープ (12)
RandomGraph[{5, 6}]RandomGraph[{6, 7}, DirectedEdges -> True]RandomGraph[BernoulliGraphDistribution[8, 0.3], 4]RandomGraph[BernoulliGraphDistribution[8, 0.3], {2, 3}]Barabasi–Albertモデルに基づいた分布に従うランダムグラフを生成する:
RandomGraph[BarabasiAlbertGraphDistribution[15, 2], 4]ベルヌーイ(Bernoulli)分布に従うランダムグラフを生成する:
RandomGraph[BernoulliGraphDistribution[8, 0.4], 4]RandomGraph[UniformGraphDistribution[8, 12], 4]RandomGraph[DegreeGraphDistribution[{3, 3, 3, 3, 3, 3, 3, 3}], 4]RandomGraph[SpatialGraphDistribution[15, 0.35], 4]RandomGraph[PriceGraphDistribution[15, 2, 1], 4]Watts–Strogatzモデルによる分布に従うランダムグラフを生成する:
RandomGraph[WattsStrogatzGraphDistribution[15, 0.2], 4]g = RandomGraph[{10^4, 10^4}];{VertexCount[g], EdgeCount[g]}オプション (70)
DirectedEdges (1)
RandomGraph[{4, 5}]DirectedEdges->Trueを使って有向グラフを生成する:
RandomGraph[{4, 5}, DirectedEdges -> True]EdgeLabels (6)
RandomGraph[{3, 3}, EdgeLabels -> {12 -> "Hello"}]el = EdgeList[RandomGraph[{3, 3}]]RandomGraph[{3, 3}, EdgeLabels -> Table[el[[i]] -> Subscript["e", i], {i, Length[el]}]]Placedを記号位置と一緒に使って辺に沿ったラベルの置き方を制御する:
Table[RandomGraph[{3, 3}, EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p], {p, {"Start", "Middle", "End"}}]Table[RandomGraph[{3, 3}, EdgeLabels -> {12 -> Placed["■■■", p]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {0, 1 / 4, 1 / 3}}]Table[RandomGraph[{3, 3}, EdgeLabels -> {12 -> Placed["■■■", {1 / 2, p}]}, PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]RandomGraph[{3, 3}, EdgeLabels -> {31 -> Placed[{"lbl1", "lbl2"}, {"Start", "End"}]}]RandomGraph[{3, 3}, EdgeLabels -> {31 -> Placed[{"lbl1", "lbl2", "lbl3"}, {"Start", "Middle", "End"}]}]TooltipとStatusAreaからの値を使って自動的にラベルを付ける:
RandomGraph[{3, 3}, EdgeLabels -> Placed["Name", Tooltip]]RandomGraph[{3, 3}, EdgeLabels -> Placed["Name", StatusArea]]EdgeShapeFunction (6)
EdgeShapeFunctionの組込み設定のリストを得る):
ResourceData["EdgeShapeFunction"]RandomGraph[{3, 3}, EdgeShapeFunction -> "Line"]Table[RandomGraph[{3, 3}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]Table[RandomGraph[{3, 3}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]Table[RandomGraph[{3, 3}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]Table[RandomGraph[{3, 3}, EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "CarvedArrow"]}]RandomGraph[{3, 3}, EdgeShapeFunction -> {12 -> "DotLine"}]RandomGraph[{3, 3}, EdgeShapeFunction -> {12 -> "BoxLine", "DotLine"}]ef[pts_List, e_] :=
Block[{s = 0.015, g = [image]}, {Arrowheads[{{s, 0.33, g}, {s, 0.67, g}}], Arrow[pts]}]RandomGraph[{3, 3}, EdgeShapeFunction -> ef]EdgeShapeFunctionはEdgeStyleと組み合せることができる:
RandomGraph[{3, 3}, EdgeStyle -> Blue, EdgeShapeFunction -> (Line[#1]&)]EdgeShapeFunctionはEdgeStyleより優先順位が高い:
RandomGraph[{3, 3}, EdgeStyle -> Blue, EdgeShapeFunction -> ({Red, Line[#1]}&)]EdgeStyle (2)
GraphHighlight (3)
RandomGraph[{3, 3}, VertexSize -> Tiny, GraphHighlight -> {1}]RandomGraph[{3, 3}, VertexSize -> Tiny, GraphHighlight -> {23}]RandomGraph[{3, 3}, VertexSize -> Tiny, GraphHighlight -> {1, 2, 12, 13}]GraphHighlightStyle (2)
GraphHighlightStyleの組込み設定のリストを得る:
ResourceData["GraphHighlightStyle"]GraphHighlightStyleの組込み設定を使う:
RandomGraph[{3, 3}, GraphHighlight -> {1, 23}, VertexSize -> Small, GraphHighlightStyle -> #, PlotLabel -> #]& /@ Select[ResourceData["GraphHighlightStyle"], # =!= Automatic&]GraphLayout (4)
RandomGraph[{3, 3}, GraphLayout -> Automatic]Table[RandomGraph[{10, 20}, GraphLayout -> l, PlotLabel -> l], {l, {"CircularEmbedding", "SpiralEmbedding"}}]Table[RandomGraph[{10, 20}, GraphLayout -> l, PlotLabel -> l], {l, {"SpringEmbedding", "SpringElectricalEmbedding", "HighDimensionalEmbedding"}}]AbsoluteOptionsを使ってレイアウトアルゴリズムを使って計算されたVertexCoordinatesを抽出する:
RandomGraph[{3, 3}]AbsoluteOptions[%, VertexCoordinates]PlotTheme (4)
基本テーマ (2)
VertexCoordinates (3)
RandomGraph[{3, 3}]AbsoluteOptionsを使って結果の頂点座標を抽出する:
AbsoluteOptions[%, VertexCoordinates]ellipseLayout[n_, {a_, b_}] := Table[{a Cos[2Pi / n u], b Sin[2Pi / n u]}, {u, 1, n}]Graphics[Point[ellipseLayout[20, {2, 1}]]]RandomGraph[{20, 25}, VertexCoordinates -> ellipseLayout[20, {2, 1}]]VertexCoordinatesはGraphLayoutより優先順位が高い:
RandomGraph[{3, 3}, VertexCoordinates -> Table[{i, i}, {i, 3}], GraphLayout -> "CircularEmbedding"]VertexLabels (13)
RandomGraph[{3, 3}, VertexLabels -> "Name"]RandomGraph[{3, 3}, VertexLabels -> {3 -> "one"}]RandomGraph[{3, 3}, VertexLabels -> Table[i -> Subscript[v, i], {i, 3}]]RandomGraph[{3, 3}, VertexLabels -> {1 -> [image], 2 -> [image], 3 -> [image]}, ImagePadding -> 30]Placedを記号位置と一緒に使って外側の位置も含むラベルの置き方を指定する:
Table[RandomGraph[{3, 3}, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p, ImagePadding -> 20], {p, {Before, After, Below, Above}}]pl = {{Before, Below}, {After, Below}, {Before, Above}, {After, Above}};Table[RandomGraph[{3, 3}, VertexSize -> 0.1, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[RandomGraph[{3, 3}, VertexSize -> 0.6, VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], VertexShapeFunction -> "Square", PlotLabel -> p], {p, {Left, Top, Right, Bottom}}]pl = {{Left, Bottom}, {Right, Bottom}, {Left, Top}, {Right, Top}};Table[RandomGraph[{3, 3}, VertexSize -> 0.6, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed["■■■", p], {i, 3}], PlotLabel -> p], {p, pl}]Table[RandomGraph[{3, 3}, VertexSize -> 0.6, ImagePadding -> 10, VertexShapeFunction -> "Square", VertexLabels -> Table[i -> Placed[[image], p], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]すべてのラベルを頂点の右上コーナー位置に置き,ラベル内の座標を変化させる:
Table[RandomGraph[{3, 3}, VertexSize -> 0.6, VertexShapeFunction -> "Square", ImagePadding -> 20, VertexLabels -> Table[i -> Placed[[image], {{1, 1}, p}], {i, 3}], PlotLabel -> p, BaselinePosition -> Bottom], {p, {{0, 0}, {1 / 2, 1 / 2}, {1, 1}}}]RandomGraph[{3, 3}, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2"}, {Above, Below}]}]RandomGraph[{3, 3}, VertexLabels -> {1 -> Placed[{"lbl1", "lbl2", "lbl3", "lbl4"}, {Above, After, Below, Before}]}]Placedの引数を使ってTooltipを含むフォーマットを制御する:
RandomGraph[{3, 3}, VertexLabels -> Placed["Name", Tooltip]]あるいはStatusAreaを含むフォーマットを制御する:
RandomGraph[{3, 3}, VertexLabels -> Placed["Name", StatusArea]]rotateLabel[lab_] := Rotate[lab, 45Degree]RandomGraph[{3, 3}, VertexLabels -> Table[i -> Placed["xxx", Below, rotateLabel], {i, 3}]]panelLabel[lab_] := Panel[lab, FrameMargins -> 0, Background -> StandardBlue]RandomGraph[{3, 3}, VertexLabels -> Table[i -> Placed["xxx", Center, panelLabel], {i, 3}]]hyperlinkLabel[lab_] := Hyperlink[lab, "http://www.wolfram.com"]RandomGraph[{3, 3}, VertexLabels -> Table[i -> Placed["xxx", Center, hyperlinkLabel], {i, 3}]]VertexShape (5)
Graphics,Image,Graphics3Dの任意のものを頂点の形として使う:
Table[RandomGraph[{3, 3}, VertexShape -> s, VertexSize -> Medium], {s, {[image], [image], [image]}}]RandomGraph[{3, 3}, VertexShape -> {2 -> [image]}, VertexSize -> Medium]VertexShapeはVertexSizeと組み合せることができる:
Table[RandomGraph[{3, 3}, VertexSize -> s, VertexShape -> [image]], {s, {Small, Large}}]VertexShapeはVertexStyleの影響を受けない:
RandomGraph[{3, 3}, VertexSize -> 0.2, VertexShape -> [image], VertexStyle -> Blue]VertexShapeFunctionはVertexShapeより優先順位が高い:
RandomGraph[{3, 3}, VertexSize -> 0.1, VertexShapeFunction -> "Square", VertexShape -> [image]]VertexShapeFunction (9)
組込みのVertexShapeFunctionコレクションのリストを得る:
ResourceData["VertexShapeFunction"]"Basic"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Basic"]Table[RandomGraph[{3, 3}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]Table[RandomGraph[{3, 3}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, {"DownTrapezoid", "UpTrapezoid", "Parallelogram", "FiveDown", "Circle", "Diamond", "Star", "Capsule"}}]"Rounded"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Rounded"]Table[RandomGraph[{3, 3}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]"Concave"コレクションのVertexShapeFunctionの組込み設定を使う:
ResourceData["VertexShapeFunction", "Concave"]Table[RandomGraph[{3, 3}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf], {vf, ResourceData["VertexShapeFunction", "Concave"]}]RandomGraph[{3, 3}, VertexShapeFunction -> { 1 -> "Square"}, VertexSize -> 0.2]RandomGraph[{3, 3}, VertexShapeFunction -> { 1 -> "Square", "Triangle"}, VertexSize -> 0.2]vf[{xc_, yc_}, name_, {w_, h_}] :=
Block[{xmin = xc - w, xmax = xc + w, ymin = yc - h, ymax = yc + h},
Polygon[{{xmin, ymin}, {xmax, ymax}, {xmin, ymax}, {xmax, ymin}}]
];RandomGraph[{3, 3}, VertexShapeFunction -> vf, VertexSize -> 0.1]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]RandomGraph[{3, 3}, VertexSize -> 0.1, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunctionはVertexStyleよりも優先順位が高い:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}RandomGraph[{3, 3}, VertexSize -> 0.1, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexShapeFunctionはVertexShapeと組み合せることができる:
RandomGraph[{3, 3}, VertexSize -> 0.3, VertexShape -> {1 -> [image]}]VertexShapeFunctionはVertexShapeより優先順位が高い:
RandomGraph[{3, 3}, VertexSize -> 0.3, VertexShapeFunction -> "Star", VertexShape -> [image]]VertexSize (8)
RandomGraph[{3, 3}, VertexSize -> Automatic]Table[RandomGraph[{3, 3}, VertexSize -> s, PlotLabel -> s], {s, {Tiny, Small, Medium, Large}}]Table[RandomGraph[{3, 3}, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}]Table[RandomGraph[{3, 3}, VertexSize -> {"Scaled", s}, PlotLabel -> {"Scaled", s}], {s, 0.1, 1, 0.3}]Table[RandomGraph[{3, 3}, VertexSize -> s, PlotLabel -> s], {s, {{0.1, 0.2}, {0.2, 0.1}}}]RandomGraph[{3, 3}, VertexSize -> {1 -> 0.2, 2 -> 0.3}]VertexSizeはVertexShapeFunctionと組み合せることができる:
Table[RandomGraph[{3, 3}, VertexSize -> s, VertexShapeFunction -> "Square", PlotLabel -> s], {s, {0.05, 0.1, 0.2}}]VertexSizeはVertexShapeと組み合せることができる:
Table[RandomGraph[{3, 3}, VertexSize -> s, VertexShape -> [image], PlotLabel -> s], {s, {0.1, 0.2, 0.4}}]VetexStyle (4)
Table[RandomGraph[{3, 3}, VertexStyle -> style, VertexSize -> 0.3, PlotLabel -> style], {style, {Yellow, EdgeForm[Dashed]}}]RandomGraph[{3, 3}, VertexStyle -> {1 -> Blue, 2 -> Red}, VertexSize -> Small]VertexShapeFunctionはVertexStyleと組み合せることができる:
vf1[{xc_, yc_}, name_, {w_, h_}] := Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]RandomGraph[{3, 3}, VertexSize -> 0.1, VertexStyle -> Blue, VertexShapeFunction -> vf1]VertexShapeFunctionはVertexStyleより優先順位が高い:
vf2[{xc_, yc_}, name_, {w_, h_}] := {Red, Rectangle[{xc - w, yc - h}, {xc + w, yc + h}]}RandomGraph[{3, 3}, VertexSize -> 0.1, VertexStyle -> Blue, VertexShapeFunction -> vf2]VertexStyleはBaseStyleと組み合せることができる:
RandomGraph[{3, 3}, VertexStyle -> LightBlue, BaseStyle -> EdgeForm[Dotted], VertexSize -> 0.2]VertexStyleはBaseStyleより優先順位が高い:
RandomGraph[{3, 3}, VertexStyle -> LightBlue, BaseStyle -> Gray, VertexSize -> 0.2]アプリケーション (3)
グラフ分布特性のランダムなでデータを生成し,そのヒストグラムと確率密度関数を比較する:
data = EdgeCount /@ RandomGraph[BernoulliGraphDistribution[10, 0.7], 10 ^ 3];𝒟 = GraphPropertyDistribution[EdgeCount[g], gBernoulliGraphDistribution[10, 0.7]];Show[Histogram[data, Automatic, "ProbabilityDensity"], DiscretePlot[PDF[𝒟, k], {k, 20, 40}, PlotStyle -> PointSize[Medium]]]ベルヌーイ(Bernoulli)グラフの頂点次数が二項分布に従うことを証明する:
data = VertexDegree[#, 1]& /@ RandomGraph[BernoulliGraphDistribution[15, 0.7], 10 ^ 3];EstimatedDistribution[data, BinomialDistribution[n, p]]Show[Histogram[data, Automatic, "ProbabilityDensity"], DiscretePlot[PDF[%, k], {k, 0, 15}, PlotStyle -> PointSize[Medium]]]各ノードのグループ内のインタラクション数が既知であるとして,インタラクションネットワークのシミュレーションを行う:
𝒢 = DegreeGraphDistribution[{2, 4, 4, 4, 3, 3, 2}];RandomGraph[𝒢, 4]特性と関係 (10)
RandomGraphは整数の頂点を使う:
g = RandomGraph[{7, 10}, VertexLabels -> "Name"]VertexList[g]VertexReplaceを使ってグラフの頂点を置換する:
VertexReplace[g, {1 -> Subscript[v, 1], 2 -> Subscript[v, 2], 3 -> Subscript[v, 3], 4 -> Subscript[v, 4], 5 -> Subscript[v, 5], 6 -> Subscript[v, 6], 7 -> Subscript[v, 7]}]VertexList[%]SeedRandomを使って反復可能なランダムグラフを得る:
{RandomGraph[{6, 5}], RandomGraph[{6, 5}]}{SeedRandom[1];RandomGraph[{6, 5}], SeedRandom[1];RandomGraph[{6, 5}]}BlockRandomを使ってRandomGraphの使用が他に影響することを防ぐ:
{BlockRandom[RandomGraph[{6, 5}]], RandomGraph[{6, 5}]}RandomVariateは確率分布から変量を生成する:
RandomVariate[NormalDistribution[]]RandomIntegerは離散一様分布に従う確率変量を生成する:
RandomInteger[{0, 10}, 10]RandomRealは連続一様分布に従う変量を生成する:
RandomReal[{0, 10}, 10]RandomChoiceはリストから置き換えるものを選ぶ無作為選択を生成する:
RandomChoice[Range[10], 10]RandomSampleはリストからの置き換えのない無作為選択を生成する:
RandomSample[Range[20], 10]RandomPrimeはランダムな素数を生成する:
RandomPrime[{1, 100}, 10]RandomImageはランダムな画像を生成する:
RandomImage[LaplaceDistribution[0, .2], {100, 100}]考えられる問題 (1)
RandomGraph[{5, 11}]RandomGraph[{n,Binomial[n,2]}]は常に n 個の頂点の完全グラフを返す:
RandomGraph[{5, 10}, 3]関連項目
BernoulliGraphDistribution UniformGraphDistribution BarabasiAlbertGraphDistribution PriceGraphDistribution WattsStrogatzGraphDistribution DegreeGraphDistribution SeedRandom
実体タイプ: Graph
インタープリタタイプ: Graph
Function Repository: RandomHypergraph
関連するガイド
-
▪
- ランダムグラフ ▪
- ソーシャルネットワーク分析 ▪
- グラフの構築と表現 ▪
- グラフとネットワーク ▪
- 科学的モデル ▪
- 乱数の生成
テキスト
Wolfram Research (2010), RandomGraph, Wolfram言語関数, 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.
APA
Wolfram Language. (2010). RandomGraph. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomGraph.html
BibTeX
@misc{reference.wolfram_2026_randomgraph, author="Wolfram Research", title="{RandomGraph}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/RandomGraph.html}", note=[Accessed: 12-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_randomgraph, organization={Wolfram Research}, title={RandomGraph}, year={2010}, url={https://reference.wolfram.com/language/ref/RandomGraph.html}, note=[Accessed: 12-November-2026]}