MCPcopy Create free account
hub / github.com/alibaba/GraphScope / gnp_random_graph

Function gnp_random_graph

python/graphscope/nx/generators/random_graphs.py:110–126  ·  view source on GitHub ↗
(n, p, seed=None, directed=False)

Source from the content-addressed store, hash-verified

108@patch_docstring(nxa.gnp_random_graph)
109@py_random_state(2)
110def gnp_random_graph(n, p, seed=None, directed=False):
111 if directed:
112 edges = itertools.permutations(range(n), 2)
113 G = nx.DiGraph()
114 else:
115 edges = itertools.combinations(range(n), 2)
116 G = nx.Graph()
117 G.add_nodes_from(range(n))
118 if p <= 0:
119 return G
120 if p >= 1:
121 return complete_graph(n, create_using=G)
122
123 for e in edges:
124 if seed.random() < p:
125 G.add_edge(*e)
126 return G
127
128
129# add some aliases to common names

Callers 1

test_random_graphMethod · 0.90

Calls 3

add_nodes_fromMethod · 0.95
add_edgeMethod · 0.95
complete_graphFunction · 0.90

Tested by 1

test_random_graphMethod · 0.72