public class RandomBTree { private static int nextLabel = 0; //print a random tree with n leaf nodes, in newick format, use nextLabel to //choose a unique label for the leaf public static void printRandomBTree(int n) { if(n == 1) System.out.print("species" + nextLabel++); else { //take a random number of leaves to go in the left subtree, the //balance go in the right subtree int split = 1 + (int)((n - 1) * Math.random()); System.out.print("("); printRandomBTree(split); System.out.print(","); printRandomBTree(n - split); System.out.print(")"); } } public static void main(String[] args) { printRandomBTree(Integer.parseInt(args[0])); System.out.println(";"); System.out.println(); System.out.print(args[0] + " species"); } }