WOLFRAM

gives a pseudorandom tree with n nodes.

RandomTree[n,k]

gives a list of k pseudorandom trees.

RandomTree[n,{k1,k2,}]

gives a k1× k2× array of trees.

Details and Options

  • RandomTree[n] samples from the discrete uniform distribution over the labeled, rooted, ordered trees of size n, where is given by CatalanNumber[n-1]. Any reordering of the data or subtrees represents a different tree. »
  • RandomTree gives a different sequence of pseudorandom trees whenever you run the Wolfram Language. By using SeedRandom, you can get a repeatable sequence. »
  • The data of the trees produced by RandomTree[n,] is taken to be integers 1, , n. »
  • RandomTree takes the same options as Tree.

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Generate a random tree with 10 nodes:

Out[5]=5

Generate a list of random trees:

Out[1]=1

Generate an array of random trees:

Out[1]=1

Options  (9)Common values & functionality for each option

Styling Individual Tree Elements  (2)

Specify the label for the generated tree element:

Out[2]=2

Specify labels and styles for subtrees by position:

Out[1]=1

Styling Entire Tree  (4)

Specify labels and styles for all subtrees:

Out[1]=1

Specify the base style:

Out[1]=1

Specify the styles for both the edges and the edges of the tree elements:

Out[1]=1

Specify the base style and styles for individual tree elements:

Out[1]=1

Tree Layout and Graphics Options  (3)

Specify the orientation for the root:

Out[1]=1

Specify a named embedding:

Out[1]=1

Specify Graphics options:

Out[1]=1

Applications  (1)Sample problems that can be solved with this function

Create a random symbolic expression:

Out[1]=1
Out[2]=2

Properties & Relations  (6)Properties of the function, and connections to other functions

RandomTree[n,] uses integers 1, , n:

Out[1]=1

Use TreeMap to replace data in the tree:

Out[2]=2

RandomTree gives pseudorandom trees:

Out[1]=1

Use SeedRandom to get repeatable random trees:

Out[2]=2

Use BlockRandom to block one use of RandomTree from affecting others:

Out[1]=1

RandomTree[n] can produce n! CatalanNumber[n-1] different trees:

Out[1]=1
Out[2]=2
Out[3]=3
Out[4]=4
Out[5]=5

RandomTree[n] samples from the uniform distribution over the labeled, rooted, ordered trees of size n:

Out[1]=1

RandomTree generates random trees of a certain size:

Out[2]=2

NestTree can be used to generate random trees with random data and numbers of children:

Out[4]=4
Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2021).
Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2021).

Text

Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2021).

Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2021).

CMS

Wolfram Language. 2021. "RandomTree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/RandomTree.html.

Wolfram Language. 2021. "RandomTree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/RandomTree.html.

APA

Wolfram Language. (2021). RandomTree. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomTree.html

Wolfram Language. (2021). RandomTree. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomTree.html

BibTeX

@misc{reference.wolfram_2025_randomtree, author="Wolfram Research", title="{RandomTree}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/RandomTree.html}", note=[Accessed: 28-April-2025 ]}

@misc{reference.wolfram_2025_randomtree, author="Wolfram Research", title="{RandomTree}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/RandomTree.html}", note=[Accessed: 28-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_randomtree, organization={Wolfram Research}, title={RandomTree}, year={2021}, url={https://reference.wolfram.com/language/ref/RandomTree.html}, note=[Accessed: 28-April-2025 ]}

@online{reference.wolfram_2025_randomtree, organization={Wolfram Research}, title={RandomTree}, year={2021}, url={https://reference.wolfram.com/language/ref/RandomTree.html}, note=[Accessed: 28-April-2025 ]}