User:Jerodast/TemplateChance

%

This template calculates the chance of drawing any of x cards out of y total possibilities in z chances, without replacement, as a percentage, where x y and z are the inputs to this template in order. Typically, used for listing the chance of Discovering some desired choices out of a total pool of options.

"Without replacement" means that the effect cannot choose the same option twice. Discover, for instance, always presents different options. Cabalist's Tome, on the other hand, can generate multiples of the same card.

Parameters

 * 1) "x" - The number of desired choices.
 * 2) "y" - The total number of choices the effect is choosing from.
 * 3) "z" - The number of chances to choose. Must be between 1 and 4, although template could be modified to support more. If not specified, defaults to 3, the number of chances offered by Discover.
 * 4) Decimal places to round to. If not specified, defaults to 1 decimal place, but 2 might be desirable for comparing very low chances. The wiki calculator will automatically avoid printing 0s in decimal places if it's an exact integer.

Examples

 * produces "".
 * 1 spell out of 5 left in the deck with Shadow Visions.
 * produces "".
 * 1 spell out of 31 available in standard format with Primordial Glyph.
 * produces "".
 * 2 "outs" on the next draw to defend against the opponent's lethal on the board, with 6 cards left in the deck.
 * produces "".
 * Any of 4 Hero Powers out of 8 offered by Sir Finley Mrrgglton.

Math
When only 1 card is desired over several chances, or there is only 1 chance to draw one of several cards, then the probability is a simple single fraction, a/b, where b is the total number of options, and a is either the number of desirable cards for a single draw, or the number of chances to draw a single card. In other words, if you draw 1 card, there's an a/b chance of that 1 being one of "a" cards you wanted. If you draw "a" cards, there's an a/b chance that the 1 you wanted was among the "a" you drew.

When one of several cards is desired, and there are multiple chances to draw, it becomes more complicated. This is most easily calculated by finding the chance to fail to draw any of the desired cards, then subtracting that from 100% to find the chance to succeed. The chance for failure gains another fractional factor with each draw chance, each one equal to "number of failure cards left"/"total number of cards left", with both numerator and denominator decreasing by 1 every time as more and more failure cards are drawn.

Example:
 * Chance to Discover neither of 2 cards in 3 chances out of 30: 28/30 * 27/29 * 26/28 = 27*26/(30*29) = 80.69%.
 * Chance to Discover one or both of 2 cards in 3 chances out of 30: 1 - the above calculation = 19.31%.