code: def generate_n_rand_probabilities_that_sum_to_m(
      n,
      m,
      *,
      max_prob=1.0,
      min_prob=0.0,
  ) -> np.ndarray:
      """
      Generates `n` random probabilities that sum to `m`.
  
      When ``min_prob=0`` and ``max_prob = 1.0``, use
      ``np.random.dirichlet(np.ones(n))*m`` instead.
  
      Parameters
      ----------
      n : int
        Length of array of random probabilities to be returned.
  
      m : float
        Sum of array of random probabilities that is returned.
  
      max_prob : float, default=1.0
        Maximum probability of any entry in the returned array. Must be between 0 and 1.
  
      min_prob : float, default=0.0
        Minimum probability of any entry in the returned array. Must be between 0 and 1.
  
      Returns
      -------
      probabilities : np.ndarray
        An array of probabilities.
      """
  
      if n == 0:
          return np.array([])
      if (max_prob + FLOATING_POINT_COMPARISON) < m / float(n):
          raise ValueError(
              "max_prob must be greater or equal to m / n, but "
              + "max_prob = "
              + str(max_prob)
              + ", m = "
              + str(m)
              + ", n = "
              + str(n)
              + ", m / n = "
              + str(m / float(n))
          )
      if min_prob > (m + FLOATING_POINT_COMPARISON) / float(n):
          raise ValueError(
              "min_prob must be less or equal to m / n, but "
              + "max_prob = "
              + str(max_prob)
              + ", m = "
              + str(m)
              + ", n = "
              + str(n)
              + ", m / n = "
              + str(m / float(n))
          )
  
      # When max_prob = 1, min_prob = 0, the next two lines are equivalent to:
      #   intermediate = np.sort(np.append(np.random.uniform(0, 1, n-1), [0, 1]))
      #   result = (intermediate[1:] - intermediate[:-1]) * m
      result = np.random.dirichlet(np.ones(n)) * m
  
      min_val = min(result)
      max_val = max(result)
      while max_val > (max_prob + FLOATING_POINT_COMPARISON):
          new_min = min_val + (max_val - max_prob)
          # This adjustment prevents the new max from always being max_prob.
          adjustment = (max_prob - new_min) * np.random.rand()
          result[np.argmin(result)] = new_min + adjustment
          result[np.argmax(result)] = max_prob - adjustment
          min_val = min(result)
          max_val = max(result)
  
      min_val = min(result)
      max_val = max(result)
      while min_val < (min_prob - FLOATING_POINT_COMPARISON):
          min_val = min(result)
          max_val = max(result)
          new_max = max_val - (min_prob - min_val)
          # This adjustment prevents the new min from always being min_prob.
          adjustment = (new_max - min_prob) * np.random.rand()
          result[np.argmax(result)] = new_max - adjustment
          result[np.argmin(result)] = min_prob + adjustment
          min_val = min(result)
          max_val = max(result)
  
      return result
  
file_path: cleanlab/cleanlab/benchmarking/noise_generation.py
imports: from typing import Optional
  import numpy
  from cleanlab.internal.util import value_counts
  from cleanlab.internal.constants import FLOATING_POINT_COMPARISON
label_desc: Use image node_id 4 for calling a global function with example usage: generate_n_rand_probabilities_that_sum_to_m(n, m) and returns: result, np