code: def multinomial_resample(weights):
      """This is the naive form of roulette sampling where we compute the
       cumulative sum of the weights and then use binary search to select the
       resampled point based on a uniformly distributed random number. Run time
       is O(n log n). You do not want to use this algorithm in practice; for some
       reason it is popular in blogs and online courses so I included it for
       reference.
  
      Parameters
      ----------
  
       weights : list-like of float
           list of weights as floats
  
       Returns
       -------
  
       indexes : ndarray of ints
           array of indexes into the weights defining the resample. i.e. the
           index of the zeroth resample is indexes[0], etc.
      """
      cumulative_sum = np.cumsum(weights)
      cumulative_sum[
          -1
      ] = 1.0  # avoid round-off errors: ensures sum is exactly one
      return np.searchsorted(cumulative_sum, random(len(weights)))
  
imports: import numpy
  from numpy.random import random
label_desc: Use image node_id 4 for calling a global function with example usage: multinomial_resample(weights) and returns: np