random_labeled_tree#
- random_labeled_tree(n, *, seed=None)[source]#
Returns a labeled tree on
nnodes 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.GraphA
networkx.Graphwith nodes in the set {0, …, n - 1}.
- Raises:
- NetworkXPointlessConcept
If
nis zero (because the null graph is not a tree).