code: private INode genDirStructure(String rootName, int maxDepth) {
      INode root = new INode(rootName);
  
      if (maxDepth>0) {
        maxDepth--;
        int minDepth = maxDepth*2/3;
        // Figure out the number of subdirectories to generate
        int numOfSubDirs = minWidth + r.nextInt(maxWidth-minWidth+1);
        // Expand the tree
        for (int i=0; i<numOfSubDirs; i++) {
          int childDepth = (maxDepth == 0)?0:
            (r.nextInt(maxDepth-minDepth+1)+minDepth);
          INode child = genDirStructure("dir"+i, childDepth);
          root.addChild(child);
        }
      }
      return root;
    }
docs: Generate a directory tree rooted at <code>rootName</code>
  The number of subtree is in the range of [minWidth, maxWidth].
  The maximum depth of each subtree is in the range of
  [2*maxDepth/3, maxDepth].