PDA

Click to See Complete Forum and Search --> : Shuffle Cards


kelemvor
May 16th, 2001, 08:31 AM
Howdy all,
I'm debating making a card game and was wondering if anyone has or knows of a function to shuffle a deck of cards. I know I can just pick random numbers and thrown out any that have already been used but if there is already a genuine card shuffler out there, I'd rather just use that.

Thanks,
--Kel

TMTOMH
May 16th, 2001, 09:38 AM
Kel,

Here's how I did it and I've seen others use the same technique. It seems to work pretty well and it's a little bit cleaner than generating the random numbers and throwing out the ones you've already used. My deck has optional Jokers so If you're not using jokers, the StyleOfGame stuff can be removed and just use "52 To 1" for the inner For loop.


Sub Shuffle(Deck() As Integer)
Randomize Timer
For I = 1 To 10
' Styleofgame has a value of either 0 or 1.
' When it's 0, we will only shuffle the first
' 52 cards. if it's 1, we'll do all 54.
For J = (52 + Styleofgame * 2) To 1 Step -1
randindex = Int(J * Rnd + 1)
Temp = Deck(J)
Deck(J) = Deck(randindex)
Deck(randindex) = Temp
Next J
Next I
End Sub


Hope this helps.