code: def random_index_based_on_weights(weights: list, rng: random.Random):
      """Generate a random index, based on index weights and a random number generator.
  
      Parameters
      ----------
      weights
          The weights of the centroid's indexes.
  
      rng
          Random number generator instance.
  
      Returns
      -------
      int
          The generated index.
  
      """
      prob_sum = sum(weights)
      val = rng.random() * prob_sum
      index = 0
      sum_value = 0.0
      while (sum_value <= val) & (index < len(weights)):
          sum_value += weights[index]
          index += 1
      return index - 1
  
file_path: river/river/datasets/synth/random_rbf.py
imports: from __future__ import annotations
  import random
  import warnings
  from river import datasets
label_desc: Use image node_id 1 for calling a global function with example usage: random_index_based_on_weights(weights, rng) and returns: unknown