|
-
May 16th, 2001, 08:31 AM
#1
Thread Starter
Member
Shuffle Cards
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
-
May 16th, 2001, 09:38 AM
#2
New Member
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.
Code:
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.
Last edited by TMTOMH; May 16th, 2001 at 09:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|