# skbio.tree.TreeNode.shuffle

`TreeNode.``shuffle`(k=None, names=None, shuffle_f=<built-in method shuffle of mtrand.RandomState object>, n=1)

  Yield trees with shuffled tip names

  State: Experimental as of 0.4.0.

  Parameters:

  k : int, optional

  > The number of tips to shuffle. If k is not None, k tips are randomly selected, and only those names will be shuffled.

  names : list, optional

  > The specific tip names to shuffle. k and names cannot be specified at the same time.

  shuffle_f : func

  > Shuffle method, this function must accept a list and modify inplace.

  n : int, optional

  > The number of iterations to perform. Value must be > 0 and np.inf can be specified for an infinite number of iterations.

  Raises:

  ValueError

  > If k is < 2 If n is < 1

  ValueError

  > If both k and names are specified

  MissingNodeError

  > If names is specified but one of the names cannot be found

  Notes

  Tip names are shuffled inplace. If neither k nor names are provided, all tips are shuffled.

  Examples

  Alternate the names on two of the tips, ‘a’, and ‘b’, and do this 5 times.

      >>> from skbio import TreeNode
      >>> tree = TreeNode.read(["((a,b),(c,d));"])
      >>> rev = lambda items: items.reverse()
      >>> shuffler = tree.shuffle(names=['a', 'b'], shuffle_f=rev, n=5)
      >>> for shuffled_tree in shuffler:
      ...     print(shuffled_tree)
      ((b,a),(c,d));

      ((a,b),(c,d));

      ((b,a),(c,d));

      ((a,b),(c,d));

      ((b,a),(c,d));