RandomTree[n]
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.
RandomTree[{e1,…,en},…]
gives trees with nodes containing the expressions ei.
RandomTree
RandomTree[n]
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.
RandomTree[{e1,…,en},…]
gives trees with nodes containing the expressions ei.
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. »
- The data of the trees produced by RandomTree[{e1,…,en},…] is taken to be expressions e1, …, en. »
- RandomTree has the same options as Tree.
-
AlignmentPoint Center the default point in the graphic to align with AspectRatio Automatic ratio of height to width Axes False whether to draw axes AxesLabel None axes labels AxesOrigin Automatic where axes should cross AxesStyle {} style specifications for the axes Background None background color for the plot BaselinePosition Automatic how to align with a surrounding text baseline BaseStyle {} base style specifications for the graphic ContentSelectable Automatic whether to allow contents to be selected CoordinatesToolOptions Automatic detailed behavior of the coordinates tool Epilog {} primitives rendered after the main plot FormatType TraditionalForm the default format type for text Frame False whether to put a frame around the plot FrameLabel None frame labels FrameStyle {} style specifications for the frame FrameTicks Automatic frame ticks FrameTicksStyle {} style specifications for frame ticks GridLines None grid lines to draw GridLinesStyle {} style specifications for grid lines ImageMargins 0. the margins to leave around the graphic ImagePadding All what extra padding to allow for labels etc. ImageSize Automatic the absolute size at which to render the graphic LabelStyle {} style specifications for labels Method Automatic details of graphics methods to use PlotLabel None an overall label for the plot PlotRange All range of values to include PlotRangeClipping False whether to clip at the plot range PlotRangePadding Automatic how much to pad the range of values PlotRegion Automatic the final display region to be filled PreserveImageOptions Automatic whether to preserve image options when displaying new versions of the same graphic Prolog {} primitives rendered before the main plot RotateLabel True whether to rotate y labels on the frame Ticks Automatic axes ticks TicksStyle {} style specifications for axes ticks
List of all options
Examples
open all close allBasic Examples (4)
Generate a random tree with 10 nodes:
RandomTree[10]Generate a list of random trees:
RandomTree[5, 3]Generate an array of random trees:
RandomTree[5, {2, 3}]Generate a tree of the lowercase letters a through z in the English alphabet:
RandomTree[Alphabet[]]Options (9)
Styling Individual Tree Elements (2)
Specify the label for the generated tree element:
RandomTree[3, TreeElementLabel -> "?"]Specify labels and styles for subtrees by position:
RandomTree[20,
TreeElementLabel -> {___, _ ? EvenQ} -> None, TreeElementStyle -> {___, _ ? OddQ} -> {LightRed, EdgeForm[{Red, Dashed}]}]Styling Entire Tree (4)
Specify labels and styles for all subtrees:
RandomTree[20, TreeElementLabel -> All -> None, TreeElementStyle -> All -> EdgeForm[Red]]RandomTree[20, BaseStyle -> LightRed]Specify the styles for both the edges and the edges of the tree elements:
RandomTree[20, BaseStyle -> {Dashed, EdgeForm[{Dashing[{}], Thick}]}]Specify the base style and styles for individual tree elements:
RandomTree[20, BaseStyle -> {Red, EdgeForm[None]}, TreeElementStyle -> All -> Opacity[0]]Tree Layout and Graphics Options (3)
Specify the orientation for the root:
RandomTree[10, TreeLayout -> Bottom]RandomTree[50, TreeLayout -> "RadialEmbedding", IconizedObject[«labels»]]Specify Graphics options:
RandomTree[50, Background -> LightBlue, ImageSize -> Full]Applications (1)
Properties & Relations (6)
RandomTree[n,…] uses integers 1, …, n:
RandomTree[7]RandomTree[{e1,…,en},…] uses expressions e1, …, en:
RandomTree[Characters["abcdefg"]]Use TreeMap to replace data in the tree:
TreeMap[Capitalize, %]RandomTree gives pseudorandom trees:
{RandomTree[6], RandomTree[6]}Use SeedRandom to get repeatable random trees:
{SeedRandom[1];RandomTree[6], SeedRandom[1];RandomTree[6]}Use BlockRandom to block one use of RandomTree from affecting others:
{BlockRandom[RandomTree[6]], RandomTree[6], RandomTree[6]}RandomTree[n] can produce n! CatalanNumber[n-1] different trees:
Table[n!CatalanNumber[n - 1], {n, 1, 8}]RandomTree[2, 20]//DeleteDuplicatesRandomTree[3, 200]//DeleteDuplicates//LengthRandomTree[4, 2000]//DeleteDuplicates//LengthRandomTree[5, 100000]//DeleteDuplicates//LengthRandomTree[n] samples from the uniform distribution over the labeled, rooted, ordered trees of size n:
RandomTree[3, 10000, IconizedObject[«image size»]]//Sort//TallyRandomTree generates random trees of a certain size:
SeedRandom[125];RandomTree[21]NestTree can be used to generate random trees with random data and numbers of children:
SeedRandom[3];NestTree[RandomInteger[10, RandomInteger[{1, 3}]]&, RandomInteger[10], 3]Related Guides
Text
Wolfram Research (2021), RandomTree, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomTree.html (updated 2025).
CMS
Wolfram Language. 2021. "RandomTree." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. 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
BibTeX
@misc{reference.wolfram_2026_randomtree, author="Wolfram Research", title="{RandomTree}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/RandomTree.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_randomtree, organization={Wolfram Research}, title={RandomTree}, year={2025}, url={https://reference.wolfram.com/language/ref/RandomTree.html}, note=[Accessed: 15-June-2026]}