approximating a shuffle with excell

sagefr0g

Well-Known Member
Canceler said:
Yes.

Are you absolutely clear on opening the VB Editor, inserting a module, and pasting the code into the module? After you've done that, at the very top of the module it says Option Explicit, and at the bottom there's a bunch of green comments followed by End Sub?

Have a seperate workbook for each version of his program, and only one of them open at a time.

Maybe you could say exactly how it's failing. A screen snip of any error message might be good.
yep i have all that.
so on his last version i get compile error syntax error in a box....
close the box and the code is hilited as in the screen shot below:
 

Attachments

k_c

Well-Known Member
aslan said:
I pressed "continue" after I came to the Stop. Does that do the same thing? There was no spreadsheet printout.
This is the code that outputs to the spreadsheet. It was not in the original version.
Code:
    Dim n As Integer
    
    Worksheets("Sheet1").Activate
    Worksheets("Sheet1").Range("A1:A416").ClearContents
    For n = 0 To DeckTot - 1
        If TheDeck(n) < 36 Then
            Worksheets("Sheet1").Cells(n + 1, 1).Value = TheDeck(n) \ 4 + 1
        Else
            Worksheets("Sheet1").Cells(n + 1, 1).Value = 10
        End If
    Next n
Paste that before or after the Stop statement. To get rid of the Stop statement altogether put an apostrophe before the word Stop so it reads 'Stop. A line beginning with an apostrophe is a comment and has no effect on execution.

You could also just delete everything in the Module and replace it with the version that includes these lines.

k_c
 

aslan

Well-Known Member
k_c said:
This is the code that outputs to the spreadsheet. It was not in the original version....

Paste that before or after the Stop statement. To get rid of the Stop statement altogether put an apostrophe before the word Stop so it reads 'Stop. A line beginning with an apostrophe is a comment and has no effect on execution.

You could also just delete everything in the Module and replace it with the version that includes these lines.

k_c
Well, that worked without a glitch. Say, it looks like it only shows the value of each card, not the suit. I thought it would give a number between 1 and 52, but that's okay. Glad to see it work. Maybe I can build on this. Thanks a lot.
 

k_c

Well-Known Member
aslan said:
Well, that worked without a glitch. Say, it looks like it only shows the value of each card, not the suit. I thought it would give a number between 1 and 52, but that's okay. Glad to see it work. Maybe I can build on this. Thanks a lot.
It can be refined to include suits. For example:
If TheDeck(n) = 0 Ace of clubs
If TheDeck(n) = 1 Ace of diamonds
If TheDeck(n) = 2 Ace of hearts
If TheDeck(n) = 3 Ace of spades
If TheDeck(n) = 4 Two of clubs
.....etc

I just output If TheDeck(n) = (0 to 3), the rank is an ace, etc.

k_c
 

aslan

Well-Known Member
k_c said:
It can be refined to include suits. For example:
If TheDeck(n) = 0 Ace of clubs
If TheDeck(n) = 1 Ace of diamonds
If TheDeck(n) = 2 Ace of hearts
If TheDeck(n) = 3 Ace of spades
If TheDeck(n) = 4 Two of clubs
.....etc

I just output If TheDeck(n) = (0 to 3), the rank is an ace, etc.

k_c
Thanks again. I've always wanted to get started with VB, so now may be a good time.
 

MrMaster

Active Member
I like the macro thing k_c!
Could you do a more advanced version of it where you can choose how many times to cut the deck and an option to see in what order the card are before the shuffle?

Edit: I personally dont understand visual basic, but if i understand your code correctly it doesnt shuffle the cards like a real riffleshuffle?
Meaning if you have a stack of 10 cards: A,2,3,4,5,6,7,8,9,10 then after the shuffle it would be A,6,2,7,3,8,4,9,5,10 or 6,A7,2,8,3,9,4,10,5

I need to learn VB :)
 
Last edited:

k_c

Well-Known Member
MrMaster said:
I like the macro thing k_c!
Could you do a more advanced version of it where you can choose how many times to cut the deck and an option to see in what order the card are before the shuffle?

Edit: I personally dont understand visual basic, but if i understand your code correctly it doesnt shuffle the cards like a real riffleshuffle?
Meaning if you have a stack of 10 cards: A,2,3,4,5,6,7,8,9,10 then after the shuffle it would be A,6,2,7,3,8,4,9,5,10 or 6,A7,2,8,3,9,4,10,5

I need to learn VB :)
This is just a computerized shuffle and it should be a good approximation of what happens in a hand shuffled game over a large number of trials. For my purposes that's all I need. It randomly exchanges card positions for a set number of times that can be controlled by input. I think QFIT's software addresses actual casino shuffles. You may want to look into his products.

k_c
 
Top