def random_tree(n, seed=None):
 if (n == 0):
  raise nx.NetworkXPointlessConcept('the null graph is not a tree')
 if (n == 1):
  return nx.empty_graph(1)
 random.seed(seed)
 sequence = sample_with_replacement(range(n), (n - 2))
 return nx.from_prufer_sequence(sequence)

def random_tree ( n , seed = None ) : if ( n == 0 ) : raise nx . NetworkXPointlessConcept ( 'the null graph is not a tree' ) if ( n == 1 ) : return nx . empty_graph ( 1 ) random . seed ( seed ) sequence = sample_with_replacement ( range ( n ) , ( n - 2 ) ) return nx . from_prufer_sequence ( sequence )
returns a uniformly random tree on n nodes .