16 Nov
2007
16 Nov
'07
8:41 p.m.
WFL said:
Brain in gear now. Generate a random integer x in the interval [0, n!-1], and express x as a mixed-radix number to the sequence of bases n,n-1,...,i,...,1 [for larger n, maybe generate directly n integers in range [0, i] for each i]. There is now a simple correspondence with the x-th permutation in alphabetic order. WFL
I think the canonical implementation of this idea is to start with the identity permutation a_i=i, and then for each i=1...n swap a_i with some random a_j for i<=j<=n. That makes it really easy to see that you can get each of the n! permutations in exactly one way. --Michael Kleber -- It is very dark and after 2000. If you continue you are likely to be eaten by a bleen.