//public Tree _tree { get; set; } static int Main(string[] args) { System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\Users\kylan_000\Desktop\tree.txt"); sw.Flush(); int depth = 0; List<Tree> _tree = new Tree(Guid.NewGuid(), depth); Random r = new Random(); int i = 10000; //this is the number of children you wand to add to the root node. sw.WriteLine("i: " + i); int j = 0; while (j < i) { _tree.AddChild(new Tree(Guid.NewGuid(), depth) { _parents = _tree }); j++; } Action<Tree, int> buildAction = (N,I) => N.AddChild(new Tree(Guid.NewGuid(), I) { _parents = N }); //foreach (Tree t in _tree._children) //{ // i = 0; // Build(ref i, ref j, ref action, t, depth++); //} //Func<Random, bool> addCondition = R => R.NextDouble() > 0.1; //this is the condition under which to add a child to the current node. Func<Random, Tree, bool> addCondition = (R, T) => R.NextDouble() * ( Math.Pow( T._depth + 1, 0.5) ) > 0.5; foreach (Tree t in _tree._children) { i = 0; Build(buildAction, t, ref r, addCondition, addCondition(r, t)); } int nodes = 0; foreach (Tree t in _tree._children) { sw.WriteLine("Parent: " + t._parents._id.ToString() +" | Node: " + t._id.ToString() + " | depth: " + t._depth); nodes++; Print(t, ref nodes, ref sw); } sw.WriteLine(nodes + " total nodes."); Console.WriteLine(nodes + " total nodes."); sw.Close(); for (; ; ) { } return 0; }