import torch g = torch.Generator().manual_seed(1234) row_perm = torch.randperm(32, generator=g) def shuffle_rows(x): # x: (C, H, W) return x[:, row_perm, :] print(row_perm[:8].tolist()) # [15, 9, 8, 1, 4, 12, 30, 7]