How to shuffle sentence based on ids?

lets’ say I have a tensor with content:
[0,55,49,38,2,0,96,28,2,0,73,2]
0 is begin of sentence token
2 is end of sentence token
I want to do random sentence permutation as like
[0,73,2,0,55,49,38,2,0,96,28,2]
or
[0,73,2,0,96,28,2,0,55,49,38,2]
how can I do it?
Thanks.

This code might work:

x = torch.tensor([0,55,49,38,2,0,96,28,2,0,73,2])
idx = torch.cat((torch.tensor([0]), torch.randperm(len(x)-2)+1, torch.tensor([len(x)-1])))
print(idx)
out = x[idx]
print(out)