Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!watserv1!70530.1226@compuserve.com
From: Mike Kent <70530.1226@CompuServe.COM>
Subject: (gradeup N roll N) is not (N deal N)
Message-ID: <930210012341_70530.1226_DHP31-1@CompuServe.COM>
Sender: root@watserv1.uwaterloo.ca
Organization: University of Waterloo
Date: Wed, 10 Feb 1993 01:23:42 GMT

In article <C258LB.1qw@news.cso.uiuc.edu>, Richard J. Gaylord
<gaylord@ux1.cso.uiuc.edu> proposes the "deal" algorithm:



 >>  chooseHistory2[lis_, n_] :=
 >>     Take[Transpose[Sort[Transpose[{Table[Random[], {Length[lis]}],
 >>        lis}]]] [[2]], n]

This is _not_ the same as APL deal, since it does not generate all
permutations equiprobably.  This is easiest to see for the case where
"lis" is (1 2) and "n" is two, where it clearly amounts to producing
(1 2)[gradeup ?2 2], which is just (origin 1)   gradeup ?2 2  .  But
?2 2   produces with equal probability (1 1), (1 2), (2 1), and (2 2),
and gradeup produces (1 2), (1 2), (2 1), and (1 2) for these vectors,
so the quoted algorithm will produce (1 2) 75% of the time.  What you
want for a fast deal is the algorithm described by madler@cco.caltech.edu
(Mark Adler) in article <1l6eaqINNqj2@gap.caltech.edu>.  I think I recall
that Knuth has a good discussion of deal algorithms in one of Vols. 1..3,
I forget which, including proving that the roll-&-swap algorithm really
produces all permutations with equal probability in the accompanying
problem set.




