Odds of having or drawing a particular card in the early parts of a Magic the Gathering (MTG) card game. by Tollie Williams

Note on nomenclature: Opening hand is 7 cards. Draw one is 8 cards. Draw two is 9 cards. etc.

Note: this page is in very raw data form, meant for data analysis, not for presentation.

Update: Somehow I broke the math here, and something's wrong. I still think it's pretty close though. I'll fix it when I get time.

Odds of having at least 1 card(s) of 4 in deck of 60:

(7) Opening hand: 39.0609%
(8 cards) Draw one: 43.4565%
(9 cards) Draw two: 48.3516%
(10 cards) Draw three: 52.8472%
(11 cards) Draw four: 55.6444%
(12 cards) Draw five: 59.0410%
(13 cards) Draw six: 62.6374%
(14 cards) Draw seven: 66.9331%
(15 cards) Draw eight: 70.7293%
(16 cards) Draw nine: 73.4266%
(17 cards) Draw ten: 75.9241%

Odds of having at least 2 card(s) of 4 in deck of 60:

(7) Opening hand: 6.4935%
(8 cards) Draw one: 8.4915%
(9 cards) Draw two: 11.4885%
(10 cards) Draw three: 14.0859%
(11 cards) Draw four: 17.0829%
(12 cards) Draw five: 20.3796%
(13 cards) Draw six: 23.3766%
(14 cards) Draw seven: 25.5744%
(15 cards) Draw eight: 28.3716%
(16 cards) Draw nine: 31.6683%
(17 cards) Draw ten: 33.3666%

Odds of having at least 3 card(s) of 4 in deck of 60:

(7) Opening hand: 0.8991%
(8 cards) Draw one: 0.8991%
(9 cards) Draw two: 1.0989%
(10 cards) Draw three: 1.3986%
(11 cards) Draw four: 2.1978%
(12 cards) Draw five: 2.6973%
(13 cards) Draw six: 3.3966%
(14 cards) Draw seven: 4.0959%
(15 cards) Draw eight: 5.1948%
(16 cards) Draw nine: 5.9940%
(17 cards) Draw ten: 7.0929%

Odds of having at least 4 card(s) of 4 in deck of 60:

(7) Opening hand: 0.0000%
(8 cards) Draw one: 0.0000%
(9 cards) Draw two: 0.0000%
(10 cards) Draw three: 0.0000%
(11 cards) Draw four: 0.0000%
(12 cards) Draw five: 0.0000%
(13 cards) Draw six: 0.0999%
(14 cards) Draw seven: 0.0999%
(15 cards) Draw eight: 0.0999%
(16 cards) Draw nine: 0.1998%
(17 cards) Draw ten: 0.2997%

Change Numbers: (below ad)

Be gentle! No validation on these numbers. PHP will (should) fail after more than 60 seconds. Numbers are very reliable (within ~ 1%) after 1000 trials.

Total Deck Size:

Cards in Deck:

Trials To Run:

Source:

License: You may use, modify, and redistribute this code, provided that you:
1) obtain my consent,
2) notify me of your improvements, and
3) give credit as such "[original] code by Tollie Williams."

Creative Commons License
odds of drawing a given card by Tollie Williams is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License.
Permissions beyond the scope of this license is available by emailing me via http://www.tollie.org. It is possible that this code is considered common property. Personally, I hope not, considering how long it took me to tweak it, but it's really not that original either. If such is the case, then this code is defacto in the Public Domain; however, if it is and if you use it, it would be good of you to link back to my website anyways, since I saved you the time and effort of producing it yourself. :)

<table style="border-spacing: 5px;">
<tr>
<?php
$deck = $_REQUEST["deck"];
$cardsInit = $_REQUEST["cardsInit"];
$times = $_REQUEST["times"];   

// init variables 
if (empty($times)) {$times = 1000;}
if (empty($deck)) {$deck = 60;}
if (empty($cardsInit)) {$cardsInit = 4;}
$cards = $cardsInit;

// init arrays
for ($y=0; $y < $cardsInit; $y++) {
   for ($z=0; $z < $deck; $z++) {
      $allTime[$y][$z]=0;
   }
}

for ($j=1; $j <= $times ; $j++) { 
   
   for ($y=0; $y < $cardsInit; $y++) { // go through countdown from cards to zero
      $cardsLeft = $y + 1;  // reset cardsLeft to hit target 
      $cards = $cardsInit; // reset number of cards left in deck
      
      for ($i=$deck; $i > 0 ; $i--) { // count down from total deck size to 0.
         // save cycles!
         if ($cards == 0) {break;} // if done looking
         if ($y > 16) {break;} // b/c they aren't relevant to the first 17 cards.
         
         $pick = rand(1,$i);  // pick random card from cards left
         if ($pick <= $cards) { // if card is picked ==
            $cardsLeft--; // cardsleft to hit target (typically 1,2,3,4)

            if ($cardsLeft == 0) $allTime[$y][$deck-$i]++;
            // nested array. allTime[# of cards we have][when drawn]
            
            ($cardsLeft == 0) ? $cards = 0 : $cards--;
            // cards left in deck for next pick if still looking for more
         }
      } 
   }
}

for ($y=0; $y < $cardsInit; $y++)  { // number of cards we have (at least)
$have = $y + 1;

   // reset for each count
   $d = 0;  // drawCount variable
   $openingHand = 0;
   $plusOne = 0;
   $plusTwo = 0;
   $plusThree = 0;
   $plusFour = 0;
   $plusFive = 0;
   $plusSix = 0;
   $plusSeven = 0;
   $plusEight = 0;
   $plusNine = 0;
   $plusTen = 0;
   
   foreach ($allTime[$y] as $k) { // go through each array
      $d++;
      // add up "found card" values from allTime for hand-sizes
      // ie. 1+2+3+4+5+6+7, then 1+2+3+4+5+6+7+8, then 1+2+3+4+5+6+7+8+9, etc.
      if ($d<=7)  { $openingHand = $openingHand + $k;} 
      if ($d<=8)  { $plusOne = $plusOne + $k;}
      if ($d<=9)  { $plusTwo = $plusTwo + $k;}
      if ($d<=10) { $plusThree = $plusThree + $k;}
      if ($d<=11) { $plusFour = $plusFour + $k;}
      if ($d<=12) { $plusFive = $plusFive + $k;}
      if ($d<=13) { $plusSix = $plusSix + $k;} 
      if ($d<=14) { $plusSeven = $plusSeven + $k;} 
      if ($d<=15) { $plusEight = $plusEight + $k;} 
      if ($d<=16) { $plusNine = $plusNine + $k;} 
      if ($d<=17) { $plusTen = $plusTen + $k;} 
   }

   // display results
   echo "<td style=\"border: 1px solid black; padding: 10px;\"><h4>Odds of having at ";
   echo "least " . $have . " card(s) of " . $cardsInit . " in deck of " . $deck . ":</h4>"; 
   echo "<p>Opening hand: "; printf ("%01.4f", 100 * $openingHand / ($j)); echo "%<br />";
   echo "Draw one: "; printf ("%01.4f", 100 * $plusOne / ($j)); echo "%<br />";
   echo "Draw two: "; printf ("%01.4f", 100 * $plusTwo / ($j)); echo "%<br />";
   echo "Draw three: "; printf ("%01.4f", 100 * $plusThree / ($j)); echo "%<br />";   
   echo "Draw four: "; printf ("%01.4f", 100 * $plusFour / ($j)); echo "%<br />";   
   echo "Draw five: "; printf ("%01.4f", 100 * $plusFive / ($j)); echo "%<br />";   
   echo "Draw six: "; printf ("%01.4f", 100 * $plusSix / ($j)); echo "%<br />";   
   echo "Draw seven: "; printf ("%01.4f", 100 * $plusSeven / ($j)); echo "%<br />";   
   echo "Draw eight: "; printf ("%01.4f", 100 * $plusEight / ($j)); echo "%<br />";   
   echo "Draw nine: "; printf ("%01.4f", 100 * $plusNine / ($j)); echo "%<br />";   
   echo "Draw ten: "; printf ("%01.4f", 100 * $plusTen / ($j)); echo "%</p></td>";   
}
?>  
</tr></table>