def gnm_random_graph(n, m, seed=None, directed=False):
 if directed:
  G = nx.DiGraph()
 else:
  G = nx.Graph()
 G.add_nodes_from(range(n))
 G.name = ('gnm_random_graph(%s,%s)' % (n, m))
 if (seed is not None):
  random.seed(seed)
 if (n == 1):
  return G
 max_edges = (n * (n - 1))
 if (not directed):
  max_edges /= 2.0
 if (m >= max_edges):
  return complete_graph(n, create_using=G)
 nlist = list(G)
 edge_count = 0
 while (edge_count < m):
  u = random.choice(nlist)
  v = random.choice(nlist)
  if ((u == v) or G.has_edge(u, v)):
   continue
  else:
   G.add_edge(u, v)
   edge_count = (edge_count + 1)
 return G

def gnm_random_graph ( n , m , seed = None , directed = False ) : if directed : G = nx . DiGraph ( ) else : G = nx . Graph ( ) G . add_nodes_from ( range ( n ) ) G . name = ( 'gnm_random_graph(%s,%s)' % ( n , m ) ) if ( seed is not None ) : random . seed ( seed ) if ( n == 1 ) : return G max_edges = ( n * ( n - 1 ) ) if ( not directed ) : max_edges /= 2.0 if ( m >= max_edges ) : return complete_graph ( n , create_using = G ) nlist = list ( G ) edge_count = 0 while ( edge_count < m ) : u = random . choice ( nlist ) v = random . choice ( nlist ) if ( ( u == v ) or G . has_edge ( u , v ) ) : continue else : G . add_edge ( u , v ) edge_count = ( edge_count + 1 ) return G
returns a g_{n .