i have a tensor x = [2, 3, 2, 1, 2, 3, 2]
I want to randomly sample a number from all same number, e.g. randomly sample the  2 from all 2’s index, and get index may be 0, namely sampled the first 2; randomly sample the 3, and get index may be 5. and randomly sample the 1, get index 3 since only single 1 exists. so the return index may like [0, 5, 3] or mask: [1, 0, 0, 1, 0, 1, 0].
I dnt know how to implement this logic by pytorch?  please kindly help me.
Thank you so much.