VBA – Probability Simulation of Two Dice

Throwing dices used to be a way to gamble. Nowadays, with TexasHoldEm all over the internet, this game is forgotten 🙂 Probably for good. Anyway, at the beginning of statistics every student is required to resolve some problems, containing dice, cards or even roulette. Combinatorics was interesting at that time. And it shows why the gambling is really a profitable business for those, who organize it.



So, everyone studying at least an hour of statistics, would be capable to come up with a similar table of probabilities for two dice:



Using this table as an input, I will build a probability simulation in VBA, in order to test it 🙂 Thus, as an input of my routine I will set the number of tests and as output I will provide the real results from the tests vs. the expected result and the difference. Pretty much something like this:



The above picture shows the results of 60 tests. We may see, that there is some difference between the expected result and  the real ones. Would this difference decrease with the increase of the number of tests? The statisticians would answer without any doubt – YES. Is this the case? See for yourself and pay attention to the third column:


Last but not least – here comes the code:

Thank you for your attention! 🙂

Tagged with: , , , ,