erdos_renyi_graph#
- erdos_renyi_graph(n, p, seed=None, directed=False, *, create_using=None)#
Returns a
random graph, also known as an Erdős-Rényi graph or a binomial graph.The
model chooses each of the possible edges with probability .- Parameters:
- nint
The number of nodes.
- pfloat
Probability for edge creation.
- seedinteger, random_state, or None (default)
Indicator of random number generation state. See Randomness.
- directedbool, optional (default=False)
If True, this function returns a directed graph.
- create_usingGraph constructor, optional (default=nx.Graph or nx.DiGraph)
Graph type to create. If graph instance, then cleared before populated. Multigraph types are not supported and raise a
NetworkXError
. By default NetworkX Graph or DiGraph are used depending ondirected
.
See also
Notes
This algorithm [2] runs in
time. For sparse graphs (that is, for small values of ),fast_gnp_random_graph()
is a faster algorithm.binomial_graph()
anderdos_renyi_graph()
are aliases forgnp_random_graph()
.>>> nx.binomial_graph is nx.gnp_random_graph True >>> nx.erdos_renyi_graph is nx.gnp_random_graph True
References
[1]Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
[2]Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).