code: def weighted_random(
      weights: np.ndarray, n_instances: int = 1
  ) -> np.ndarray:
      """
      Returns n_instances indices based on the weights.
  
      Args:
          weights: Contains the weights of the sampling.
          n_instances: Specifies how many indices to return.
  
      Returns:
          n_instances random indices based on the weights.
      """
      assert (
          n_instances <= weights.shape[0]
      ), "n_instances must be less or equal than the size of utility"
      weight_sum = np.sum(weights)
      assert (
          weight_sum > 0
      ), "the sum of weights must be larger than zero"
  
      random_idx = np.random.choice(
          range(len(weights)),
          size=n_instances,
          p=weights / weight_sum,
          replace=False,
      )
      return random_idx
  
imports: import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: weighted_random(weights, n_instances) and returns: random_idx