home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.programming:2615 comp.theory:1928 sci.math.num-analysis:2732
- Path: sparky!uunet!olivea!spool.mu.edu!darwin.sura.net!haven.umd.edu!mimsy!cvl!zogwarg!hoey
- From: hoey@zogwarg.etl.army.mil (Dan Hoey)
- Newsgroups: comp.programming,comp.theory,sci.math.num-analysis
- Subject: Re: Proving fair shuffles (was: FULL HOUSE)
- Message-ID: <1152@zogwarg.etl.army.mil>
- Date: 15 Sep 92 17:33:21 GMT
- References: <schnitzi.716563018@eola.cs.ucf.edu> <1992Sep13.223147.28768@wuecl.wustl.edu> <LOWRY.92Sep14133846@rotor.watson.ibm.com> <prn5c10@fido.asd.sgi.com> <1992Sep14.184939.10440@austin.eds.com> <dak.716561621@messua>
- Followup-To: comp.programming
- Organization: Naval Research Laboratory, Washington, DC
- Lines: 47
-
- schnitzi@cs.ucf.edu (Mark Schnitzius) writes:
-
- >Assuming you have a true random number generator, is there
- >a way to _prove_ that a particular algorithm performs an
- >honest shuffle (i.e. each card has equal possibility of
- >being in each place)? Are there any order(n) shuffling
- >routines?
-
- Yes, and yes, and the algorithm's in Knuth, and it's faqfully posted
- here and there (it was in comp.sources.d less than a month ago)
- possibly because it's a frequently assigned homework exercise. But
- that still doesn't prevent mtj@babar.asd.sgi.com (Michael Jones) from
- posting the egregious pseudo-shuffle
-
- bad> for (card = 0; card < 52; card++)
- bad> {
- bad> swap = random() % 52;
- bad> temp = deck[card];
- bad> deck[card] = deck[swap];
- bad> deck[swap] = temp;
- bad> }
-
- or yenne@austin.eds.com (Britt Yenne) from misshuffling the first five
- cards with lossage like
-
- bad> for(i = 0; i < 5; i++)
- bad> {
- bad> n = random() % 52;
- bad> s = card[n];
- bad> card[n] = card[i];
- bad> card[i] = s;
- bad> }
-
- Even dak@messua.informatik.rwth-aachen.de (David Kastrup), offering
- the good advice to
-
- > Use rand/(MAXUNSIGNED/52 + 1) instead of rand%52.
-
- doesn't mention that always folding rand to a 52-element range is the
- commonest, most obvious sign of an incompetent shuffler.
-
- But, you may notice, I have not provided a corrected shuffling
- algorithm! Think of it as an incentive to go read Knuth, or a Pons
- Asinorum for the lazy student.
-
- Dan Hoey
- Hoey@AIC.NRL.Navy.Mil
-