Article View: comp.theory
Article #1876Re: Generating a Random Permutation
From: Joseph G. Niederberger
Date: Thu, 28 Jan 1993 21:43
Date: Thu, 28 Jan 1993 21:43
29 lines
1759 bytes
1759 bytes
In article <C1FpMw.4Ip@ccu.umanitoba.ca> sbloch@silver.cs.umanitoba.ca (Stephen Bloch) writes: >sumner@math.scarolina.edu (David Sumner) writes: >>> In an earlier post I wrote that an easy way to generate a >>> random permutation of the integers 1-n was: >>> > ++++++++++++++ >>> > Initialize A[n] as the array [1, 2, 3, 4,..., n] >>> > for i=1 to n >>> > z = random(n) >>> > t = a[i] >>> > a[i] = a[z] >>> > a[z] = t >>> > next i >>> > ++++++++++++++ >>> There is a typo in this. The line 'z = random(n)' should >>> be 'z = random(i)' > >and "Thomas W. Strong, Jr." <strong+@CMU.EDU> replies: >>I have to agree with the algorithm as originally presented. What it >>effectively does is it takes each item and puts it in a random position. >><stuff deleted> >No, the original algorithm is incorrect (for the simple combinatorial >reason several people have posted). This is counterintuitive to a degree that it reminds me of the famous "Monte Hall" flap of a couple years back. There must be some way to make money from this... ;^) Joe N.
Technical Details
Message-ID:
<1993Jan28.214325.17733@walter.bellcore.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!ames!pacbell.com!att-out!walter!homebrew!jgnReferences:
<sumner.727366153@milo.math.scarolina.edu> <4fKlI4200WB8Aps_9A@andrew.cmu.edu> <C1FpMw.4Ip@ccu.umanitoba.ca>Show Full Headers
Complete Article Headers
Newsgroups: comp.theory,sci.crypt,rec.puzzles Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!ames!pacbell.com!att-out!walter!homebrew!jgn From: jgn@homebrew.bellcore.com (Joseph G. Niederberger) Subject: Re: Generating a Random Permutation Message-ID: <1993Jan28.214325.17733@walter.bellcore.com> Sender: news@walter.bellcore.com Nntp-Posting-Host: homebrew.bellcore.com Reply-To: jgn@homebrew.UUCP (Joseph G. Niederberger) Organization: Bellcore, Morristown, NJ References: <sumner.727366153@milo.math.scarolina.edu> <4fKlI4200WB8Aps_9A@andrew.cmu.edu> <C1FpMw.4Ip@ccu.umanitoba.ca> Date: Thu, 28 Jan 93 21:43:25 GMT Lines: 30