Probability Calculator

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]



Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only



Many people, I suspect,  have  trouble with probability problems, even when you think you understand the concepts.  Like rate problems ( a chicken and a half lays an egg and a half in a day and a half...), or crossword puzzles, it seems that the more you solve, the easier they get.  

As a result of difficulty with a specific problem a couple of weeks ago, I decided that a generalized probability calculator would be a handy tool to have.  Being optimistic by nature, I thought, "how hard can it be?".  As usual, harder than I  thought.     

The result posted today does a good job of solving the simplest probability types, those with only two outcomes (success/fail, true/false. heads/tails, red/not red, etc.) and from two common types of experiments.  

bulletBernoulli trials, those which have two outcomes and are independent of previous trials of the same experiment.
bulletHypergeometric trials which have two outcomes but are not independent because each experiment  removes one or more samples from the population being tested.   Dealing cards from a deck or drawing balls from bag are common examples.       

Neither this page nor the program will work well as a tutorial - others have done a better job than I ever could - but it may be useful in solving problems or verifying solutions to problems you have solved on your own.

The rest of the universe of probability problems did not seem to fall into easily presented templates.   I suspect such templates exist, but I just have not solved enough problems yet to recognize them.  As an alternative, I added a page with a generalized arithmetic expression evaluator including an upgrade to add Fact and Combo functions to calculate factorials and combination values.  

The general  procedure learned in solving sample problems for this program is to get the probability for a specific single instance  of the situation to be tested and then multiply that by the number of ways other instances could occur.  So, for example, to calculate the probability of rolling a pair if 3 dice are thrown we can proceed this way:

bulletThe probability of {1,1,2} is 1/6*1/6*1/6=1/216 (or 1 case out of 216 possible if you prefer to think of it that way) .
bullet The "1" could be one of 6 numbers and the "2" could be any one of the other 5 so the probability of {N, N, not N} is 6*5*(1/216)=30/216.
bulletNow the N's could  appear in other places, specifically the  number ways to select two spots for the N's is  the number ways to pick two locations out of the three available, denoted "3 choose 2" or 3C2 or for my programs Combo(3,2).  the answer is 3.  By the way, you could also choose the number of ways to choose a location for the "not N", 3C1   which is, of course, also 3.  So our final probability calculation is 3*(30/216) = 90/216=0.417.  (I hope!.)

Well, as usual, have fun, if you find problems with my code or sample problems please send feedback so I can fix it.  

 Non-programmers are welcome to read on, but may want to skip to the bottom of this page to download executable version of the program.         

Notes for programmer's 

Most of the problems with implementing the program were mathematical not programming.  It took a bit to figure out how to extend the TExParser class to include Fact and Combo functions.     

The program uses  units from our DFF Library so a one-time download of DFFLIBV05 or later will be required to recompile the program.  

Addendum November 15, 2012:  Version 2  posted today adds the ability to define, save, and reload additional probability problems in the Advanced Problems sections. 

There are 4 field types saved with each problem:
bulletProblem name,
bulleta one line problem description,
bulletthe expression which calculates the probability of a single trial, and
bullet a 4 line "Rationale" section to describe how the expression represents the successful outcomes to be divided by total possible outcomes to produce the probability.


Running/Exploring the Program 

bulletDownload source
bulletDownload current DFF library file (DFFLibV15 )
bulletDownload  executable

Suggestions for Further Explorations

bullet More problem templates?  Nov. 15, 2012: Even better, Version 2 allows users to define, solve and save additional problems,
bullet Code to intercept parsing and evaluation errors in the expression evaluator.  Current default error reporting is OK, but not integrated into the program.   


Created: March19, 2006 

Modified: July 29, 2017

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.