🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #1151

Re: Card Shuffling

#1151
From: David Toland
Date: Wed, 11 Nov 1992 16:33
40 lines
2245 bytes
In article <1992Nov11.170046.11528@siesoft.co.uk> huw@siesoft.co.uk (Huw Roberts) writes:
>Try this one (guarantees that each possible ordering is equally likely given
>a perfectly random random number generator).
>
>    for (i = NUM_CARDS; i > 0; i--)
>	r = random number between 1 and i inclusive
>	swap card[i] and card[r] (may be the same card)

Uh, C uses 0-based arrays.  Should be:

    for (i = NUM_CARDS - 1; i >= 0; i--)
        {
	r = random number between 0 and i-1 inclusive
	swap card[i] and card[r] (may be the same card)
        }

This is essentially the same as a response I gave via email, but using
a single deck instead of two.  My method (in pseudocode) was:

unshuffled_deck_count = 52
do while unshuffled_deck_count != 0
    take card unshuffled_deck[random(0..unshuffled_deck_count-1)]
    append card to shuffled_deck
    --unshuffled_deck_count
    end;

A problem I pointed out with this approach is that it may be TOO
random.  If you're trying to model a card game accurately, you
may want to simulate the patterns of non-randomness that result
from human methods of shuffling.  For example, riffling the cards
tends to leave sequences of cards in the same order, or a pair of
such sequences intermixed but not randomized beyond that.

Simulating the shuffling patterns of human players requires more
sophisticated algorithms and is measurably slower.  It CAN make
a difference in the actual play.  Some card players can get a good
idea from a shuffled deck what game it was last used for.
-- 
det@phlan.sw.stratus.com   |  "Laddie, you'll be needin' something to wash
                           |  that doon with."
Technical Details
Message-ID: <1drcleINNgqe@transfer.stratus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!network.ucsd.edu!swrinde!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!bu.edu!transfer.stratus.com!phlan.sw.stratus.com!det
References: <1992Nov6.163008.19400@csi.uottawa.ca> <1992Nov11.170046.11528@siesoft.co.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!network.ucsd.edu!swrinde!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!bu.edu!transfer.stratus.com!phlan.sw.stratus.com!det
From: det@phlan.sw.stratus.com (David Toland)
Newsgroups: rec.games.programmer
Subject: Re: Card Shuffling
Message-ID: <1drcleINNgqe@transfer.stratus.com>
Date: 11 Nov 92 16:33:50 GMT
References: <1992Nov6.163008.19400@csi.uottawa.ca> <1992Nov11.170046.11528@siesoft.co.uk>
Organization: Stratus Computer, Software Engineering
Lines: 40
NNTP-Posting-Host: phlan.sw.stratus.com