code: def _fold_tie_break(
      desired_samples_per_fold, M, random_state=check_random_state(None)
  ):
      """Helper function to split a tie between folds with same desirability of a given sample
  
      Parameters
      ----------
      desired_samples_per_fold: np.array[Float], :code:`(n_splits)`
          number of samples desired per fold
      M : np.array(int)
          List of folds between which to break the tie
  
      random_state : None | int | np.random.RandomState
          the random state seed (optional)
  
      Returns
      -------
      fold_number : int
          The selected fold index to put samples into
      """
      if len(M) == 1:
          return M[0]
      else:
          max_val = max(desired_samples_per_fold[M])
          M_prim = np.where(
              np.array(desired_samples_per_fold) == max_val
          )[0]
          M_prim = np.array([x for x in M_prim if x in M])
          if random_state:
              if isinstance(random_state, np.random.RandomState):
                  return random_state.choice(M_prim, 1)[0]
              else:
                  np.random.seed(random_state)
          return np.random.choice(M_prim, 1)[0]
  
file_path: scikit-multilearn/skmultilearn/model_selection/iterative_stratification.py
imports: from sklearn.model_selection._split import _BaseKFold
  import numpy
  import scipy.sparse
  import itertools
  from sklearn.utils import check_random_state
label_desc: Use image node_id 2 for calling a global function with example usage: _fold_tie_break(desired_samples_per_fold, M, random_state) and returns: M, np, random_state