// Generate Random Tree of depth N public void GenrateTree(int depth, NodeTree <T> node, T nodeData) { if (depth <= 1) { return; } int randomChildCount = rand.Next(1, 5); for (int i = 0; i < randomChildCount; i++) { node.SpawnChild(Guid.NewGuid(), nodeData); } // ToList used to resolve "Collection was modified; enumeration operation may not execute." node.children.ToList().ForEach(n => GenrateTree(depth - 1, n, nodeData)); }