code: def naive_weighted_choices(rs, weights, size=None):
      """
      Select indices at random, weighted by the iterator `weights` of
      arbitrary (non-negative) floats. That is, `x` will be returned
      with probability `weights[x]/sum(weights)`.
  
      For doing a single sample with arbitrary weights, this is much (5x
      or more) faster than numpy.random.choice, because the latter
      requires a lot of preprocessing (normalized probabilties), and
      does a lot of conversions/checks/preprocessing internally.
      """
      probs = np.cumsum(weights)
      total = probs[-1]
      if total == 0:
          # all weights were zero (probably), so we shouldn't choose anything
          return None
  
      thresholds = rs.random() if size is None else rs.random(size)
      idx = np.searchsorted(probs, thresholds * total, side="left")
  
      return idx
  
imports: import numpy
  import warnings
  from collections import defaultdict, deque
  from scipy import stats
  from scipy.special import softmax
  from ..core.schema import GraphSchema
  from ..core.graph import StellarGraph
  from ..core.utils import is_real_iterable
  from ..core.validation import require_integer_in_range, comma_sep
  from ..random import random_state
  from abc import ABC, abstractmethod
label_desc: Use image node_id 2 for calling a global function with example usage: naive_weighted_choices(rs, weights, size) and returns: idx, None