code: def _select_random_candidates(cands, num):
      """
      Args:
          cands (list[obj])
          num (int or float)
  
      Returns:
          list[obj]
      """
      if isinstance(num, int) and num >= 0:
          rand_cands = random.sample(cands, min(num, len(cands)))
      elif isinstance(num, float) and 0.0 <= num <= 1.0:
          rand_cands = [cand for cand in cands if random.random() < num]
      else:
          raise ValueError(
              f"num={num} is invalid; must be an int >= 0 or a float in [0.0, 1.0]"
          )
      return rand_cands
  
file_path: textacy/src/textacy/augmentation/transforms.py
imports: from __future__ import annotations
  import random
  from typing import Optional
  from cytoolz import itertoolz
  from ..None import errors, types, utils
  from .None import utils
label_desc: Use image node_id 10 for calling a global function with example usage: _select_random_candidates(cands, num) and returns: rand_cands