Thanks, I replaced the algorithm. Now the distribution of permutations is much closer to uniform.