def gnp_random_graph(n, p, seed=None, directed=False):
 if directed:
  G = nx.DiGraph()
 else:
  G = nx.Graph()
 G.add_nodes_from(range(n))
 G.name = ('gnp_random_graph(%s,%s)' % (n, p))
 if (p <= 0):
  return G
 if (p >= 1):
  return complete_graph(n, create_using=G)
 if (not (seed is None)):
  random.seed(seed)
 if G.is_directed():
  edges = itertools.permutations(range(n), 2)
 else:
  edges = itertools.combinations(range(n), 2)
 for e in edges:
  if (random.random() < p):
   G.add_edge(*e)
 return G

def gnp_random_graph ( n , p , seed = None , directed = False ) : if directed : G = nx . DiGraph ( ) else : G = nx . Graph ( ) G . add_nodes_from ( range ( n ) ) G . name = ( 'gnp_random_graph(%s,%s)' % ( n , p ) ) if ( p <= 0 ) : return G if ( p >= 1 ) : return complete_graph ( n , create_using = G ) if ( not ( seed is None ) ) : random . seed ( seed ) if G . is_directed ( ) : edges = itertools . permutations ( range ( n ) , 2 ) else : edges = itertools . combinations ( range ( n ) , 2 ) for e in edges : if ( random . random ( ) < p ) : G . add_edge ( * e ) return G
returns a g_{n .