Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

gnp_random_graph

gnp_random_graph(n, p, seed=None, directed=False)[source]

Return a random graph G_{n,p} (Erdős-Rényi graph, binomial graph).

Chooses each of the possible edges with probability p.

This is also called binomial_graph and erdos_renyi_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 return a directed graph

Notes

This is an O(n^2) algorithm. For sparse graphs (small p) see fast_gnp_random_graph for a faster algorithm.

References

[R313]
  1. Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
[R314]
    1. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).