🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #1047

Re: Card Shuffling

#1047
From: Bits of Magic
Date: Tue, 10 Nov 1992 07:42
25 lines
964 bytes
A quick and dirty way is:

	Card	deck[DECKSIZE];

	for (i=0;i<DECKSIZE;i++)
		deck[i] = i;

	for (i=0;i<SWAPS;i++) {
		firstcard = random(DECKSIZE);
		secondcard = random(DECKSIZE);
		temp = deck[firstcard];
		deck[firstcard] = deck[secondcard];
		deck[secondcard] = temp;
	}

where your Card values run from 0 to DECKSIZE (say 52 or 54), random(N)
returns a random integer in the range 0 to N-1 (inclusive), and SWAPS
is (as I recall from a project many years ago) at least about 100.

Basically it's just:
	swap two randomly selected cards in the deck
	repeat as needed

hope it helps,
	evan 
Technical Details
Message-ID: <69216@cup.portal.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!portal!cup.portal.com!HeroSoftware
References: <1992Nov6.163008.19400@csi.uottawa.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!portal!cup.portal.com!HeroSoftware
From: HeroSoftware@cup.portal.com (Bits of Magic)
Newsgroups: rec.games.programmer
Subject: Re: Card Shuffling
Message-ID: <69216@cup.portal.com>
Date: Mon,  9 Nov 92 23:42:51 PST
Organization: The Portal System (TM)
References:  <1992Nov6.163008.19400@csi.uottawa.ca>
Lines: 25