I'm looking for an algorithm to randomly generate permutations on 1:n, which though have a defined bubblesort distance d from 1:n, e.g. (2,3,1) and (3,1,2) are distance 1 from (1,2,3), (2,3,1) and (3,1,2) are d=2, finally (3,2,1) is d=3.
Naive approach is to flip a random sorted pair d times, however it seems it does not produce an uniform sample... The exact approach (generate all permutations at a given d and then sample) does not scale too well.