def dense_gnm_random_graph(n, m, seed=None):
 mmax = ((n * (n - 1)) / 2)
 if (m >= mmax):
  G = complete_graph(n)
 else:
  G = empty_graph(n)
 G.name = ('dense_gnm_random_graph(%s,%s)' % (n, m))
 if ((n == 1) or (m >= mmax)):
  return G
 if (seed is not None):
  random.seed(seed)
 u = 0
 v = 1
 t = 0
 k = 0
 while True:
  if (random.randrange((mmax - t)) < (m - k)):
   G.add_edge(u, v)
   k += 1
   if (k == m):
    return G
  t += 1
  v += 1
  if (v == n):
   u += 1
   v = (u + 1)

def dense_gnm_random_graph ( n , m , seed = None ) : mmax = ( ( n * ( n - 1 ) ) / 2 ) if ( m >= mmax ) : G = complete_graph ( n ) else : G = empty_graph ( n ) G . name = ( 'dense_gnm_random_graph(%s,%s)' % ( n , m ) ) if ( ( n == 1 ) or ( m >= mmax ) ) : return G if ( seed is not None ) : random . seed ( seed ) u = 0 v = 1 t = 0 k = 0 while True : if ( random . randrange ( ( mmax - t ) ) < ( m - k ) ) : G . add_edge ( u , v ) k += 1 if ( k == m ) : return G t += 1 v += 1 if ( v == n ) : u += 1 v = ( u + 1 )
returns a g_{n .