random_labeled_tree#

random_labeled_tree(n, *, seed=None)[source]#

Returns a labeled tree on n nodes chosen uniformly at random.

Generating uniformly distributed random Prüfer sequences and converting them into the corresponding trees is a straightforward method of generating uniformly distributed random labeled trees. This function implements this method.

Parameters:
nint

The number of nodes, greater than zero.

seedrandom_state

Indicator of random number generation state. See Randomness

Returns:
networkx.Graph

A networkx.Graph with nodes in the set {0, …, n - 1}.

Raises:
NetworkXPointlessConcept

If n is zero (because the null graph is not a tree).