code: def indices_around_random_pivot(
      databuffer,
      target_batch_numel,
      max_batch_size=None,
      max_batch_numel=None,
      max_padding_ratio=0.2,
      randint_generator=random.randint,
  ):
      """Random pivot sampler_fn for dynamic_bucketed_batch
  
      Create a batch around a random pivot index in the sorted buffer
  
      This works on the databuffer which is assumed to be in sorted order. An
      index is chosen at random. This starts the window of indices: at first,
      only the randomly chosen pivot index is included. The window of indices is
      grown one-index-at-a-time, picking either the index to the right of the
      window, or the index to the left, picking the index that would increase the
      padding ratio the least, and making sure the batch wouldn't exceed the
      maximum batch length nor the maximum padding ratio.
  
      Arguments
      ---------
      databuffer : list
          Sorted list of LengthItems
      target_batch_numel : int
          Target of total batch length including padding, which is simply computed
          as batch size * length of longest example. This function aims to return
          the batch as soon as the gathered length exceeds this. If some limits
          are encountered first, this may not be satisifed.
      max_batch_size : None, int
          Maximum number of examples to include in the batch, or None to not limit
          by number of examples.
      max_batch_numel : None, int
          Maximum of total batch length including padding, which is simply computed
          as batch size * length of longest example.
  
      """
      bufferlen = len(databuffer)
      if max_batch_size is None:
          max_batch_size = bufferlen
      # Choose pivot:
      min_index = max_index = randint_generator(0, bufferlen - 1)
      lengths = [databuffer[min_index].length]
  
      # Define index filtering function:
      def possibly_consider(index, to_consider):
          """Adds an index to the to_consider list, f the index passes all
          requirements."""
          if index < 0 or index >= len(databuffer):
              return
          consideree = databuffer[index]
          updated_lengths = [consideree.length] + lengths
          if max_batch_numel is not None:
              updated_total = total_length_with_padding(updated_lengths)
              if updated_total > max_batch_numel:
                  return
          updated_ratio = padding_ratio(updated_lengths)
          if (
              max_padding_ratio is not None
              and updated_ratio > max_padding_ratio
          ):
              return
          to_consider.append(RatioIndex(updated_ratio, index))
  
      # Loop till the target length is exceeded or max batch size is hit:
      while (
          max_index + 1 - min_index < max_batch_size
          and total_length_with_padding(lengths) < target_batch_numel
      ):
          # Consider indices to the left and to the right, if they
          # pass the requirements:
          to_consider = []
          possibly_consider(min_index - 1, to_consider)
          possibly_consider(max_index + 1, to_consider)
          # If neither pass the requirements, then we must return the batch
          # as it is now (there can be no better addition):
          if not to_consider:
              break
          # Pick the index that minimizes the padding ratio increase:
          to_add = min(to_consider)
          min_index = min(min_index, to_add.index)
          max_index = max(max_index, to_add.index)
          lengths.append(databuffer[to_add.index].length)
      return list(range(min_index, max_index + 1))
  
file_path: speechbrain/speechbrain/dataio/iterators.py
imports: import bisect
  import random
  from dataclasses import dataclass, field
  from functools import partial
  from typing import Any
  from speechbrain.dataio.batch import PaddedBatch
label_desc: Use image node_id 3 for calling a global function with example usage: indices_around_random_pivot(databuffer, target_batch_numel, max_batch_size, max_batch_numel, max_padding_ratio, randint_generator) and returns: list