code: def random_replacement_(
      batch: torch.LongTensor,
      index: int,
      selection: slice,
      size: int,
      max_index: int,
  ) -> None:
      """
      Replace a column of a batch of indices by random indices.
  
      :param batch: shape: `(*batch_dims, d)`
          the batch of indices
      :param index:
          the index (of the last axis) which to replace
      :param selection:
          a selection of the batch, e.g., a slice or a mask
      :param size:
          the size of the selection
      :param max_index:
          the maximum index value at the chosen position
      """
      # At least make sure to not replace the triples by the original value
      # To make sure we don't replace the {head, relation, tail} by the
      # original value we shift all values greater or equal than the original value by one up
      # for that reason we choose the random value from [0, num_{heads, relations, tails} -1]
      replacement = torch.randint(
          high=max_index - 1,
          size=(size,),
          device=batch.device,
      )
      replacement += (replacement >= batch[selection, index]).long()
      batch[selection, index] = replacement
  
file_path: pykeen/src/pykeen/sampling/basic_negative_sampler.py
imports: import math
  from typing import Collection, Optional
  import torch
  from .negative_sampler import NegativeSampler
  from ..constants import LABEL_HEAD, LABEL_TAIL, TARGET_TO_INDEX
  from ..typing import Target
label_desc: Use image node_id 1 for calling a global function with example usage: random_replacement_(batch, index, selection, size, max_index) without return types