Hi everyone, I'm new to the forum but I've been lurking for a while when I run into questions on something I'm doing.
I haven't been able to find an answer to my question this time: what happens when you want to deal card hands iteratively? I have some code that deals 15 of 52 cards randomly into column A, but then when I run the same code for thousands of hands, I get some strange results. In the game, each of the six players gets two cards and then there are three community cards, hence the need for 15 cards.
I ran my iterative process for 8000 hands yesterday and ended up with 22 fours of a kind, which seems like a lot more than I should be seeing in just 8000 hands. The individual hand-dealing code is below as well as the iterative code I'm using:
The bottom of the Hands() code just copies and pastes the results into a Master sheet, it shouldn't have anything to do with the actual iteration and randomization of the hands I'm seeing. Is my Hands() code interacting in any strange way with the OneHand() code during the iterations to give me these strange results? Is the OneHand() code not as random as I think it is? I didn't create the OneHand() code, I found it online someplace, so if it's not random, I may need some help creating a better one.
I haven't been able to find an answer to my question this time: what happens when you want to deal card hands iteratively? I have some code that deals 15 of 52 cards randomly into column A, but then when I run the same code for thousands of hands, I get some strange results. In the game, each of the six players gets two cards and then there are three community cards, hence the need for 15 cards.
I ran my iterative process for 8000 hands yesterday and ended up with 22 fours of a kind, which seems like a lot more than I should be seeing in just 8000 hands. The individual hand-dealing code is below as well as the iterative code I'm using:
Code:
Sub OneHand()
Sheets("Raw").Select
Dim NumArray, SuitArray, AllCards() As Variant
Dim MyCard As String
Dim x, i, MySuit, MyNum, MyVal As Integer
'Load Cards Into the array AllCards
NumArray = Array("14", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13")
SuitArray = Array("h", "s", "c", "d")
x = 1
For MySuit = LBound(SuitArray) To UBound(SuitArray)
For MyNum = LBound(NumArray) To UBound(NumArray)
ReDim Preserve AllCards(1 To x)
AllCards(x) = NumArray(MyNum) & SuitArray(MySuit)
x = x + 1
Next MyNum
Next MySuit
'Randomly distribute cards to column A, removing the card that was last
'picked from the array of available cards.
For x = 2 To 16
Randomize
MyVal = Int(((UBound(AllCards) - (x - 1)) * Rnd()) + 1)
MyCard = AllCards(MyVal)
For i = MyVal To UBound(AllCards) - 1
AllCards(i) = AllCards(i + 1)
Next i
Cells(x, "A").Value = MyCard
Next x
End Sub
Code:
Sub Hands()a = 1
For a = 1 To 8000
Application.Run ("OneHand")
Application.Calculate
Sheets("Raw").Select
Range("E128:J128").Select
Selection.Copy
Sheets("Master").Select
Cells(a, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Raw").Select
Range("E129:J129").Select
Selection.Copy
Sheets("Master").Select
Cells(a, 7).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Next a
End Sub
The bottom of the Hands() code just copies and pastes the results into a Master sheet, it shouldn't have anything to do with the actual iteration and randomization of the hands I'm seeing. Is my Hands() code interacting in any strange way with the OneHand() code during the iterations to give me these strange results? Is the OneHand() code not as random as I think it is? I didn't create the OneHand() code, I found it online someplace, so if it's not random, I may need some help creating a better one.