Skip to main content
`Ctrl`+`K`

# fast_gnp_random_graph

fast_gnp_random_graph(n, p, seed=None, directed=False, *, create_using=None)

  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 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.

    create_using Graph 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 on `directed`.

  See also

  `gnp_random_graph`

  Notes

  The \(G_{n,p}\) graph algorithm chooses each of the \([n (n - 1)] / 2\) (undirected) or \(n (n - 1)\) (directed) possible edges with probability \(p\).

  This algorithm [1] runs in \(O(n + m)\) time, where `m` is the expected number of edges, which equals \(p n (n - 1) / 2\). This should be faster than `gnp_random_graph()` when \(p\) is small and the expected number of edges is small (that is, the graph is sparse).

  References

  [1]

  Vladimir Batagelj and Ulrik Brandes, “Efficient generation of large random networks”, Phys. Rev. E, 71, 036113, 2005.