code: def _generate_randperm_indices(
      *, size: int, generator: torch.Generator
  ):
      """Generate the indices of a random permutation."""
      dtype = _get_torch_dtype(size)
      # This is actually matching PyTorch's CPU implementation, see: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/TensorFactories.cpp#L900-L921
      perm = torch.arange(size, dtype=dtype)
      for i in range(size):
          j = torch.randint(
              i, size, size=(1,), generator=generator
          ).item()
  
          # Always swap even if no-op
          value = perm[j].item()
          perm[j] = perm[i].item()
          perm[i] = value
          yield value
  
imports: import itertools
  from typing import Any, Optional
  import warnings
  import numpy
  import torch
  from torch.utils.data.sampler import Sampler
  import dinov2.distributed
label_desc: Use image node_id 3 for calling a global function with example usage: _generate_randperm_indices() without return types