Article View: rec.games.programmer
Article #1147Re: Card Shuffling
From: Iain McCord
Date: Wed, 11 Nov 1992 13:03
Date: Wed, 11 Nov 1992 13:03
22 lines
1254 bytes
1254 bytes
In article <1992Nov9.223125.20083@unislc.uucp> ttobler@unislc.uucp (Trent Tobler) writes:
> for i = 1 to NUM_CARDS
> r = random number between 1 and NUM_CARDS
^ should be i
> swap card[i] and card[r]
> end for
>As long as the random generator is reasonably random, this will shuffle the
>deck.
The unmodified algorithm has N**N different shuffles. There are only N!
possible permutations. As N! doesn't divide N**N evenly, some of the N!
permutations will be repeated more than others. The modified algorithm
gives N! shuffles, and all of the possible permutations are repeated once.
How useful that modification is depends on the cycle length of the
pseudo random number generator.
--
~~~~~/\~~~~~
Iain McCord ~~~~/()\~~~~ Wed Nov 11 13:03:42 WET 1992
~~~~~~~~~~~~
Technical Details
Message-ID:
<10924@baird.cs.strath.ac.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!uknet!strath-cs!imccReferences:
<1992Nov6.163008.19400@csi.uottawa.ca> <1992Nov9.223125.20083@unislc.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!uknet!strath-cs!imcc From: imcc@cs.strath.ac.uk (Iain McCord) Newsgroups: rec.games.programmer Subject: Re: Card Shuffling Message-ID: <10924@baird.cs.strath.ac.uk> Date: 11 Nov 92 13:03:50 GMT References: <1992Nov6.163008.19400@csi.uottawa.ca> <1992Nov9.223125.20083@unislc.uucp> Organization: Comp. Sci. Dept., Strathclyde Univ., Glasgow, Scotland. Lines: 22