Yes, your code looks good and seems to work fine:
batch = torch.cat((torch.zeros(4, 2, 4, 2), torch.ones(4, 2, 4, 2)), dim=3)
print(batch)

perm = torch.randperm(batch.size(0))
idx = perm[:batch.size(0)//2]
batch[idx] = batch[idx].flip(3)

print(batch)