def generate_random_graph(node_num, edge_num, self_loops=False, multi_edges=False):
 g = Graph.Graph()
 if (not multi_edges):
  if self_loops:
   max_edges = (node_num * node_num)
  else:
   max_edges = (node_num * (node_num - 1))
  if (edge_num > max_edges):
   raise GraphError("inconsistent arguments to 'generate_random_graph'")
 nodes = range(node_num)
 for node in nodes:
  g.add_node(node)
 while 1:
  head = random.choice(nodes)
  tail = random.choice(nodes)
  if ((head == tail) and (not self_loops)):
   continue
  if ((g.edge_by_node(head, tail) is not None) and (not multi_edges)):
   continue
  g.add_edge(head, tail)
  if (g.number_of_edges() >= edge_num):
   break
 return g

def generate_random_graph ( node_num , edge_num , self_loops = False , multi_edges = False ) : g = Graph . Graph ( ) if ( not multi_edges ) : if self_loops : max_edges = ( node_num * node_num ) else : max_edges = ( node_num * ( node_num - 1 ) ) if ( edge_num > max_edges ) : raise GraphError ( "inconsistent arguments to 'generate_random_graph'" ) nodes = range ( node_num ) for node in nodes : g . add_node ( node ) while 1 : head = random . choice ( nodes ) tail = random . choice ( nodes ) if ( ( head == tail ) and ( not self_loops ) ) : continue if ( ( g . edge_by_node ( head , tail ) is not None ) and ( not multi_edges ) ) : continue g . add_edge ( head , tail ) if ( g . number_of_edges ( ) >= edge_num ) : break return g
generates and returns a :py:class:~altgraph .