Article View: comp.theory
Article #1915Re: Looking for random permutation generation algorithms
From: David Karr
Date: Fri, 08 Jan 1993 16:39
Date: Fri, 08 Jan 1993 16:39
34 lines
2120 bytes
2120 bytes
Aaargh. Somehow, in my effort to get the permutation algorithm from my head to a clear written explanation, I managed to flub at least two key points. Prof. Meyerson points out both of them: In article <2607@usna.NAVY.MIL> mdm@math3.sma.usna.navy.mil (Mark D. Meyerson -- math FACULTY <mdm@sma.usna.navy.mil>) writes: >This method fails. There is a minor error in that letting >p=0 and using modular arithmetic gives zero values outside >of the subscript range of the arrays. This is easily >patched. True. I should have indexed both arrays v and w from 0 to N-1 in the first place, and initialized t to N-1 as well. I hope this fixes this error. > But a major error is that k mod b won't >distinguish between different k. The first example of this >failure is for N=4 and k=4 or 16 (N!=24 so both k values occur.) This is really the major omission from the algorithm. I had meant to compute both k mod b *and* k div b. k mod b is used to index the array for the current selection; k div b is then copied to k for the next round. With the division step properly included in the algorithm, the resulting permutations for k=4 and k=16 are 1,4,3,2 and 1,2,4,3 respectively. If you get different results then most likely I have made some other error in the description of the algorithm. Actually I suspect my algorithm may be fundamentally the same as another one that was posted that was supposedly based on FORTRAN multidimensional array indexing, but I came down with a bad case of MEGO when I looked at the FORTRAN code so I can't say for sure. -- David Karr (karr@cs.cornell.edu)
Technical Details
Message-ID:
<1993Jan8.163909.20820@cs.cornell.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!gatech!rpi!batcomputer!cornell!karrReferences:
<1993Jan6.014749.15323@ee.ubc.ca> <1993Jan7.165939.11149@cs.cornell.edu> <2607@usna.NAVY.MIL>Show Full Headers
Complete Article Headers
Newsgroups: comp.theory,sci.crypt,sci.math,rec.puzzles Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!rpi!batcomputer!cornell!karr From: karr@cs.cornell.edu (David Karr) Subject: Re: Looking for random permutation generation algorithms Message-ID: <1993Jan8.163909.20820@cs.cornell.edu> Organization: Cornell Univ. CS Dept, Ithaca NY 14853 References: <1993Jan6.014749.15323@ee.ubc.ca> <1993Jan7.165939.11149@cs.cornell.edu> <2607@usna.NAVY.MIL> Date: Fri, 8 Jan 1993 16:39:09 GMT Lines: 37