code: def random_tree(n_leaves):
      
      def _random_subtree(leaves):
          if len(leaves) == 1:
              return leaves[0]
          elif len(leaves) == 2:
              return (leaves[0], leaves[1])
          else:
              split = npr.randint(1, len(leaves)-1)
              return (_random_subtree(leaves[:split]),
                      _random_subtree(leaves[split:]))
  
      return _random_subtree(np.arange(n_leaves))
docs: Randomly partition the nodes