private Node makeNode ( Random rng , int maxDepth ) { if ( functionProbability . nextEvent ( rng ) && maxDepth > 1 ) { // Max depth for sub-trees is one less than max depth for this node. int depth = maxDepth - 1 ; switch ( rng . nextInt ( 5 ) ) { case 0 : return new Addition ( makeNode ( rng , depth ) , makeNode ( rng , depth ) ) ; case 1 : return new Subtraction ( makeNode ( rng , depth ) , makeNode ( rng , depth ) ) ; case 2 : return new Multiplication ( makeNode ( rng , depth ) , makeNode ( rng , depth ) ) ; case 3 : return new IfThenElse ( makeNode ( rng , depth ) , makeNode ( rng , depth ) , makeNode ( rng , depth ) ) ; default : return new IsGreater ( makeNode ( rng , depth ) , makeNode ( rng , depth ) ) ; } } else if ( parameterProbability . nextEvent ( rng ) ) { return new Parameter ( rng . nextInt ( parameterCount ) ) ; } else { return new Constant ( rng . nextInt ( 11 ) ) ; } }
Recursively constructs a tree of Nodes up to the specified maximum depth .