Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: shuffling a deck of cards

  • To: mathgroup at
  • Subject: [mg31781] Re: shuffling a deck of cards
  • From: "Bart van der Wolf" <bvdwolf at>
  • Date: Sun, 2 Dec 2001 04:24:53 -0500 (EST)
  • References: <9ua3bv$17h$>
  • Sender: owner-wri-mathgroup at

"Peter Dimitriou" <peterangelo at> wrote in message
news:9ua3bv$17h$1 at
> To Whom it may concern,
> the following is a deck of cards that needs to be shuffled, how would
> I do this using the Sort Command
> Clubset=Array[clubs, 13]
> {clubs[1],clubs[2],clubs[3],clubs[4],clubs[5],clubs[6],clubs[7],clubs[8],
>   clubs[9],clubs[10],clubs[11],clubs[12],clubs[13]}
> Diamondset=Array[diamonds, 13]
> {diamonds[1],diamonds[2],diamonds[3],diamonds[4],diamonds[5],diamonds[6],
>   diamonds[13]}
> Spadeset=Array[Spade, 13]
> {Spade[1],Spade[2],Spade[3],Spade[4],Spade[5],Spade[6],Spade[7],Spade[8],
>   Spade[9],Spade[10],Spade[11],Spade[12],Spade[13]}
> Heartset=Array[Heart, 13]
> {Heart[1],Heart[2],Heart[3],Heart[4],Heart[5],Heart[6],Heart[7],Heart[8],
>   Heart[9],Heart[10],Heart[11],Heart[12],Heart[13]}
> FullDeck=Sort[Join[{Heartset},{Spadeset}, {Diamondset}, {Clubset}]]
> {{clubs[1],clubs[2],clubs[3],clubs[4],clubs[5],clubs[6],clubs[7],clubs[8],
>     clubs[9],clubs[10],clubs[11],clubs[12],clubs[13]},{diamonds[1],
>     diamonds[8],diamonds[9],diamonds[10],diamonds[11],diamonds[12],
>     diamonds[13]},{Heart[1],Heart[2],Heart[3],Heart[4],Heart[5],Heart[6],
>     Heart[7],Heart[8],Heart[9],Heart[10],Heart[11],Heart[12],
>     Heart[13]},{Spade[1],Spade[2],Spade[3],Spade[4],Spade[5],Spade[6],
>     Spade[7],Spade[8],Spade[9],Spade[10],Spade[11],Spade[12],Spade[13]}}
> How do I shuffle FullDeck using the Sort Command so it is all mixed
> up?

I am not sure why you set the FullDeck up as an Array instead of a List, but
perhaps this method helps solving your question:

For[fd=Flatten[FullDeck]; i=52, i>1, i--,
  j=Random[Integer, {1, i}]; {fd[[i]], fd[[j]]}={fd[[j]], fd[[i]]}];

Now fd is a shuffled list (not an array as you set it up). You may want to
include SeedRandom[n] if you want to reproduce a shuffle or avoid it.
Increasing the startvalue i=52 with multiples of 52 will allow to shuffle
multiple decks.


  • Prev by Date: Re: shuffling a deck of cards
  • Next by Date: Re: Path finding in graph theory, Lookig for your help,
  • Previous by thread: Re: shuffling a deck of cards
  • Next by thread: RE: shuffling a deck of cards