How to generate a random graph given the number of nodes and edges?

Kush Jain picture Kush Jain · Dec 3, 2013 · Viewed 15.2k times · Source

I am using python with igraph library:

from igraph import *
g = Graph()
g.add_vertices(4)
g.add_edges([(0,2),(1,2),(3,2)])
print g.betweenness()

I would like to generate a random graph with 10000 nodes and 100000 edges. The edges can be random. Please suggest a way to have random edges (using numpy.random.rand )

Answer

Tamás picture Tamás · Dec 3, 2013

Do you have to use numpy.random.rand? If not, just use Graph.Erdos_Renyi, which lets you specify the number of nodes and edges directly:

g = Graph.Erdos_Renyi(n=10000, m=100000)