code: def reservoir_r(data, n):
      """!
      @brief Performs data sampling using Reservoir Algorithm R.
      @details Algorithm complexity O(n). Implementation is based on paper @cite article::utils::sampling::1. Average
                number of uniform random variates: \f$N - n\f$.
  
      @param[in] data (list): Input data for sampling.
      @param[in] n (uint): Size of sample that should be extracted from 'data'.
  
      @return (list) Sample with size 'n' from 'data'.
  
      Generate random samples with 5 elements and with 3 elements using Reservoir Algorithm R:
      @code
          data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
          sample = reservoir_r(data, 5)   # generate sample with 5 elements for 'data'.
          print(sample)
  
          sample = reservoir_r(data, 3)   # generate sample with 3 elements for 'data'.
          print(sample)
      @endcode
  
      Output example for the code above:
      @code
          [20, 7, 17, 12, 11]
          [12, 2, 10]
      @endcode
  
      """
      if n > len(data):
          raise ValueError(
              "Incorrect sampling value 'n' (%d) that should be bigger then data size (%d)."
          )
  
      random.seed()
      reservoir = data[0:n]
  
      for i in range(n, len(data)):
          m = random.randrange(0, i + 1)
          if m < n:
              reservoir[m] = data[i]
  
      return reservoir
  
label_desc: Use image node_id 1 for calling a global function with example usage: reservoir_r(data, n) and returns: reservoir