code: def _rademacher_sampler(indices, num_params, *args, rng):
      r"""Sample a random vector with (independent) entries from {+1, -1} with balanced probability.
      That is, each entry follows the
      `Rademacher distribution. <https://en.wikipedia.org/wiki/Rademacher_distribution>`_
  
      The signature corresponds to the one required for the input ``sampler`` to ``spsa_grad``:
  
      Args:
          indices (Sequence[int]): Indices of the trainable tape parameters that will be perturbed.
          num_params (int): Total number of trainable tape parameters.
          rng (np.random.Generator): A NumPy pseudo-random number generator.
  
      Returns:
          tensor_like: Vector of size ``num_params`` with non-zero entries at positions indicated
          by ``indices``, each entry sampled independently from the Rademacher distribution.
      """
      # pylint: disable=unused-argument
      direction = np.zeros(num_params)
      direction[indices] = rng.choice([-1, 1], size=len(indices))
      return direction
  
file_path: pennylane/pennylane/gradients/spsa_gradient.py
imports: from typing import Sequence, Callable
  from functools import partial
  import numpy
  import pennylane
  from pennylane import transform
  from pennylane.gradients.gradient_transform import _contract_qjac_with_cjac
  from pennylane.transforms.tape_expand import expand_invalid_trainable
  from .finite_difference import _processing_fn, finite_diff_coeffs
  from .gradient_transform import _all_zero_grad, assert_no_tape_batching, choose_trainable_params, find_and_validate_gradient_methods, _no_trainable_grad
  from .general_shift_rules import generate_multishifted_tapes
label_desc: Use image node_id 1 for calling a global function with example usage: _rademacher_sampler(indices, num_params) and returns: direction