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


binomial_graph(n, p, seed=None, directed=False)

Returns a \(G_{n,p}\) random graph, also known as an Erdős-Rényi graph or a binomial graph.

The \(G_{n,p}\) model chooses each of the possible edges with probability \(p\).

The functions binomial_graph() and erdos_renyi_graph() are aliases of this function.

  • n (int) – The number of nodes.
  • p (float) – Probability for edge creation.
  • seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.
  • directed (bool, optional (default=False)) – If True, this function returns a directed graph.


This algorithm [2] runs in \(O(n^2)\) time. For sparse graphs (that is, for small values of \(p\)), fast_gnp_random_graph() is a faster algorithm.


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