Card Drawing Probabilities

Ronin Storm

Administrator
Staff member
A question for the more mathematically minded of you:

I have a small deck of cards.

There are ten cards in the deck, and they are numbered 1 to 10.

I want to draw three cards from the deck.

How likely is it that I am going to draw at least one 10 in those three draws, given that I do not return cards to the deck while I'm drawing the three?

How about if I draw only two cards?

How about if there are twenty cards in the deck, two copies of each of 1 to 10?

There's a solution to this sort of problem but I don't know the name of the solution so I can't research it...

(All this in aid of a bit of game design, by the by.)
 

Tetsuo_Shima

In Cryo Sleep
First attempt you have a 1 in 10 chance 10%.

Second attempt you have a 1 in 9 chance 11.1%

Third attempt you have a 1 in 8 chance 12.5%

Total that up (46.23%) chance.

You can work out the percentage chance of drawing a card from a 1-10 numbered deck, but you can't add.
 

Ronin Storm

Administrator
Staff member
As Tetsuo says, the probabilities for these can't sum. e.g. 4 card set, 1 chance of success, 3 draws. First draw, 25%. Second draw 33%. Third draw 50%. Chance of drawing inside three draws not equal to 108%.

However, inspired by the links and finding the various web site explanations to be totally mystifying, I believe the general case to be presented in the following VBA:

Code:
Function DrawProb(deckSize, successCount, drawCount)

If deckSize <= drawCount Then

    DrawProb = 1
    
ElseIf drawCount = 0 Then

    DrawProb = 0

ElseIf successCount = 0 Then

    DrawProb = 0

Else

    failCount = deckSize - successCount
    
    FailProduct = 1
    DeckProduct = 1
    
    For i = 1 To drawCount Step 1
    
        FailProduct = FailProduct * failCount
        DeckProduct = DeckProduct * deckSize
        
        failCount = failCount - 1
        deckSize = deckSize - 1
        
    Next i
    
    DrawProb = 1 - (FailProduct / DeckProduct)

End If

End Function
 

Ronin Storm

Administrator
Staff member
That said... I'm not entirely sure that this is giving me the right results.

In a 6 card deck, values of 1 to 6, with just one 6, the chances of drawing a 6 on at least one of 2 draws is (apparently) 33.3%.

In a 12 card deck, values 1 to 6, with two 6's, the chances of drawing a 6 on a least one of 2 draws is (apparently) 31.8%.

Should they be the same?

[edit]Actually...[/edit]

Looked into it.

The first instance has a 16.7% (1 in 6) chance on the first draw and a 20% (1 in 5) chance on the second draw.

However, the second instance has the same 16.7% (2 in 12) chance on the first draw but a reduced 18.1% chance on the second draw (2 in 11).

How's that for a surprise?
 

Huung

Well-Known Member
You might also want to look into the maths of conditional probability, as this is what this kind of thing comes under usually. (The whole x blue balls and y red balls in a bag, what are the chances z balls are blue etc).

Edit:

Might not be what you're looking for, but I was thinking something like this.
 

thatbloke

Junior Administrator
I believe, thinking back 10 years to my A-Levels, that conditional probability is what you require here.

The probability of an outcome given that another "thing" has already occurred.
 

Huung

Well-Known Member
I believe, thinking back 10 years to my A-Levels, that conditional probability is what you require here.

The probability of an outcome given that another "thing" has already occurred.

A levels? It's GCSE maths ;)
 

Ronin Storm

Administrator
Staff member
Again, thanks for the links. I'm sufficiently far away from the maths of it that the notation is the thing that's killing me. What the hell is:

Code:
P(B|A)

Is that the probability of B or A? If so, how does that differ from:

Code:
P(A|B)

...? 'Cause, logically speaking, I can't see that it does.

Either way, I'm pretty sure my code gives the right answer, now.
 

thatbloke

Junior Administrator
The first is the probability of B, given A.

The second is the probability of A, given B.

Not necessarily the same. (By the way I can't for the life of me remember how it all works, but I remember hating it. LOTS. :D )
 

Huung

Well-Known Member
Heh, in code you'd normally read | as 'or', but as bloke said, it's a 'given that'.

Basically:

Code:
P (B|A) = P (A and B)
          -----------
             P (A)

This allows you to work out the probability of an event, given than another event's probability is known, as well as the probability of both events occurring.
 

Iron_fist

Super Moderator
Staff member
there is some stuff in one of my inf and maths courses i'm sure i can find the notes online if you want
 

Wol

In Cryo Sleep
c'mon guys, this isnt rocket science!

Code:
|----------------------------------|
|----------!A----------|-----A-----|
|------!B-------|-----B----|---!B--|

|-------1-------|--2---|-3-|---4---|


1 = P(!B | !A)
2 = P(B | !A)
3 = P(B | A)
4 = P(!B | A)

so you can also see that for P (A | B) = #3 / #3 + #2 if you just take the probability line for B and see where A overlaps.

Thats how I deal with probabilities anyway. Lines are awesome :p
 

Ronin Storm

Administrator
Staff member
Nope, still confused. ;)

I just don't follow the notation at all because it doesn't boil down to a workable formula for me. All very logical, not very useful, at least to me.

Practically, I think my formula actually looks like:

Code:
P = 1 - ((n * (n - 1) * (n - 2)) / (d * (d - 1) * (d - 2)))

P is the probability.
d is the size of the deck.
n is the number of failures in the deck, which is d minus the number of possible successes.

The number of components above and below the line in the n/d construct is governed by the number of card draws. i.e. The above represents 3 draws.

There's a limiter in my code where d is less than or equal to the number of draws (which is always a probability of 1), or where n = d (P = 0) or where there are no draws (P = 0). Probably should cover the instance where d is zero (P = 0) but that's not needed for my purposes.
 

Huung

Well-Known Member
I have NO idea what wol just did. I was roughly following the other stuff.

Wol just basically took a Venn diagram, and flattened it into a line :p

What you have there looks good to me at first glance, Ronin.

If you wanted to know the number of ways of picking x cards from a deck d big, you'd have a formula like:

Code:
(d C x) =       d!
           -----------
          ((d-x)! * x!)

Once you have your number of ways, the chance of doing said action becomes "1 in" this many ways.

Ie. Something like the lottery. You have 49 balls, 6 draws, you can have the balls in any order to still win. So the formula would be:

Code:
49! / 6!

The reason for the lack of (d-x)! is due to the balls being able to be drawn in any order. If the order had to be specific, you'd be looking at:

Code:
49! / ((49-6)! * 6!)

Which are just really bad odds :p
 
Top