Article View: rec.games.programmer
Article #1038Re: Card Shuffling
From: Trent Tobler
Date: Mon, 09 Nov 1992 22:31
Date: Mon, 09 Nov 1992 22:31
24 lines
1044 bytes
1044 bytes
U. N. derGrad (u519876@csi.UOttawa.CA) wrote: : Hi there, : : I'm looking for a quick and simple algorithm for shuffling a normal : deck of cards. A joker or two could also be added to the deck (I'm : making a poker game). : : Any suggestions? Programming language is C, on a Unix station. : : Much appreciated, make a single pass through the array of cards, and swap each card with another card chosen at random: ie: for i = 1 to NUM_CARDS r = random number between 1 and NUM_CARDS swap card[i] and card[r] end for As long as the random generator is reasonably random, this will shuffle the deck. -- Trent Tobler - ttobler@unislc.slc.unisys.com
Technical Details
Message-ID:
<1992Nov9.223125.20083@unislc.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!unislc!ttoblerReferences:
<1992Nov6.163008.19400@csi.uottawa.ca>Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!unislc!ttobler From: ttobler@unislc.uucp (Trent Tobler) Subject: Re: Card Shuffling X-Newsreader: Tin 1.1 PL5 References: <1992Nov6.163008.19400@csi.uottawa.ca> Message-ID: <1992Nov9.223125.20083@unislc.uucp> Organization: Unisys Corporation SLC Date: Mon, 9 Nov 1992 22:31:25 GMT Lines: 24