Solved by ptrblck in post #4 
              
              
                In that case the indexing with idx created by randperm should work and you could skip the last part. This would shuffle the x tensor in dim1.