fast_gnp_random_graph¶
-
fast_gnp_random_graph
(n, p, seed=None, directed=False)[source]¶ Returns a
G_{n,p}
random graph, also known as an Erdős-Rényi graph or a binomial graph.Parameters: - n (int) – The number of nodes.
- p (float) – Probability for edge creation.
- seed (int, optional) – Seed for random number generator (default=None).
- directed (bool, optional (default=False)) – If True, this function returns a directed graph.
Notes
The
G_{n,p}
graph algorithm chooses each of the[n (n - 1)] / 2
(undirected) orn (n - 1)
(directed) possible edges with probabilityp
.This algorithm runs in
O(n + m)
time, wherem
is the expected number of edges, which equalsp n (n - 1) / 2
. This should be faster thangnp_random_graph()
whenp
is small and the expected number of edges is small (that is, the graph is sparse).See also
References
[1] Vladimir Batagelj and Ulrik Brandes, “Efficient generation of large random networks”, Phys. Rev. E, 71, 036113, 2005.