monte carlo

A Ruby Monte Carlo simulation of coin flips

For some reason or another today I was curious about this question: If you flipped a coin ten times, what are the odds that the coin would come up heads ten times, or tails ten times)?

I'm sure there is a way to determine this statistically, but I don't know how to do that, so, being new to Ruby, I wrote a little Ruby simulation program — essentially a Monte Carlo simulation of the problem — to find the answer. (Pretty boring, I know, but hey, I was bored, interested in learning Ruby, and didn't feel like reading any more of The Stand right now.)

A “Minority Report” Monte Carlo simulation in Scala

“The Precogs are never wrong. But occasionally they do disagree.”
~ Minority Report

This article shares the source code for a Monte Carlo simulation that I wrote in Scala. It was inspired by the movie Minority Report, as well as my own experience.


For the purposes of this simulation, imagine that you have three people that are each “right” roughly 80% of the time. For instance, if they take a test with 100 questions, each of the three individuals will get 80 of the questions right, although they may not get the same questions right or wrong. Given these three people, my question to several statisticians was, “If two of the people have the same answer to a given question, what are the odds that they are correct? Furthermore, if all three of them give the same answer to a question, what are the odds that they are right?”

A Java Monte Carlo simulation for my “Minority Report” problem


This Java Monte Carlo simulation tutorial, and the corresponding Java program, was inspired by the story and subsequent movie "Minority Report", as well as my recent interest in Monte Carlo simulations.