Warning

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

networkx.algorithms.bipartite.generators.random_graph

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

Return a bipartite random graph.

This is a bipartite version of the binomial (Erdős-Rényi) graph.

Parameters:
  • n (int) – The number of nodes in the first bipartite set.
  • m (int) – The number of nodes in the second bipartite set.
  • 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 function is not imported in the main namespace. To use it you have to explicitly import the bipartite package.

The bipartite random graph algorithm chooses each of the n*m (undirected) or 2*nm (directed) possible edges with probability p.

This algorithm is \(O(n+m)\) where \(m\) is the expected number of edges.

The nodes are assigned the attribute ‘bipartite’ with the value 0 or 1 to indicate which bipartite set the node belongs to.

See also

gnp_random_graph(), configuration_model()

References

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