Wolfram Alpha:

```Monte-Carlo Methods
-------------------

The Monte Carlo method is just one of many methods for analyzing
uncertainty propagation, where the goal is to determine how random
variation, lack of knowledge, or error affects the sensitivity,
performance, or reliability of the system that is being modeled.

Monte Carlo simulation is categorized as a sampling method because
the inputs are randomly generated from probability distributions to
simulate the process of sampling from an actual population. So, we try
to choose a distribution for the inputs that most closely matches data
we already have, or best represents our current state of knowledge.
The data generated from the simulation can be represented as probability
distributions (or histograms) or converted to error bars, reliability
predictions, tolerance zones, and confidence intervals.

------
|      |
---x1--|      |---y1
---x2--| f(x) |
---x3--|      |---y2
|      |
------

1.  Create a parametric model y = f(x1,x2,...xn)
2.  Generate a random set of inputs x1,x1,...xn
3.  Evaluate the model and store the results as yn
4.  Repeat steps 2 and 3 for i = 1 to n
5.  Analyze the results using histograms, summary statistics,
confidence intervals, etc.

Example:  Compute the value of π

Inscribe circle inside square with sides x = 1, y = 1.  Consider

y
|
|.
|   .
1 |     .
|      .
|       .
------------ x
1

Area of quadrant = π/4

Area of square = 4

Generate random combination of x and y between 0 and 1.  From
Pythagoras:

if √(x2 + y2) <= 1 then count as a 'hit'.  if √(x2 + y2) > 1 then
count as a 'miss'.

4 * hits
π  =  ---------------
(hits + misses)

It is simple to write a simple javascript program to do this:

var hits = 0;
var i = 0;
var pi = 0;
var x = 0;
var y = 0;
var hyp = 0;
for(i=0; i<=1000000; i++)
{
x = Math.random();
y = Math.random();
hyp = Math.sqrt((x*x)+(y*y));

if(hyp <= 1)
{
hits++;
}
}

pi = (4*hits)/i;

function displaypi(){
var hits = 0;
var i = 0;
var pi = 0;
var x = 0;
var y = 0;
var hyp = 0;
for(i=0; i<=1000000; i++)
{
x = Math.random();
y = Math.random();
hyp = Math.sqrt((x*x)+(y*y));

if(hyp <= 1)
{
hits++;
}
}

pi = (4*hits)/i;

alert("and the answer is ... " + pi);
}

compute π
```