home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.programming:2613 comp.theory:1925
- Path: sparky!uunet!wupost!psuvax1!rutgers!sgigate!odin!fido!babar.asd.sgi.com!mtj
- From: mtj@babar.asd.sgi.com (Michael Jones)
- Newsgroups: comp.programming,comp.theory
- Subject: Re: Proving fair shuffles (was: FULL HOUSE)
- Message-ID: <psqghc8@fido.asd.sgi.com>
- Date: 15 Sep 92 16:21:53 GMT
- References: <schnitzi.716563018@eola.cs.ucf.edu>
- Sender: news@fido.asd.sgi.com (Usenet News Admin)
- Distribution: comp
- Organization: Silicon Graphics, Inc.
- Lines: 39
-
- In article <...>, schnitzi@cs.ucf.edu (Mark Schnitzius) writes:
- |> I've been wondering...
- |>
- |> Assuming you have a true random number generator, is there
- |> a way to _prove_ that a particular algorithm performs an
- |> honest shuuffle (i.e. each card has equal possibility of
- |> being in each place)? Are there any order(n) shuffling
- |> routines?
- |>
- |> Mark Schnitzius
- |> schnitzi@eola.cs.ucf.edu
- |> University of Central Florida
-
- Certainly such an algorithm exists, and is O(n):
-
- old: array of cards in some order {such as a new deck}
- new: empty array
-
- while (old not empty)
- begin
- select a card in old at random
- remove card from old
- add card to new (anywhere: front, back, ...)
- end
-
- This will do just what you ask. Since "remove a card" and
- "select a card" are messy for arrays (requires moving
- cards down after removal, multiple random probes, or the
- advance-and-skip loop) a more common sequence is the one
- in my posted solution:
-
- old: array of 52 cards in any order
-
- for (i = 0; i < 52; i++)
- swap card[i] and card[random() % 52];
-
- -- Michael Jones mtj@sgi.com 415.390.1455 M/S 7L-590
- Silicon Graphics, Advanced Graphics Division
- 2011 N. Shoreline Blvd., Mtn. View, CA 94039-7311
-