π Estimation (Monte Carlo)
Estimate π by Monte Carlo: 4 × (points inside unit circle / total).
Estimating π by Monte Carlo
Throw n random points uniformly into the unit square [0,1]² and count how many fall inside the quarter unit circle (x² + y² ≤ 1). Since the quadrant has area π/4 and the square has area 1, the ratio k/n converges to π/4, so π ≈ 4·k/n. Convergence is slow — error scales as 1/√n. Example: 1,000 points → π with ~3% error; 1,000,000 points → ~0.1% error. The method was introduced by Stanislaw Ulam and John von Neumann at Los Alamos around 1946 for neutron-transport simulations during the Manhattan Project.
Applications
High-dimensional numerical integration (the only family that escapes the curse of dimensionality), physical simulation (neutron transport, lattice QCD), finance (option pricing via Black-Scholes-Monte-Carlo), reinforcement learning (MCTS in AlphaGo / AlphaZero) and Bayesian inference (MCMC — Markov Chain Monte Carlo).
FAQ
Why is convergence so slow? Standard error of a Monte Carlo estimator is σ/√n. To gain one decimal place of precision you need 100× more samples.
Why use it if it's slow? In high dimensions deterministic quadratures cost exponentially in dim; Monte Carlo stays at 1/√n regardless of dimension — the only practical option above ~6–8 dimensions.
How can I reduce variance? Importance sampling, stratified sampling, antithetic variables, control variates, and quasi-Monte Carlo (Sobol, Halton) which achieves nearly 1/n.
Related Tools
CI for Difference of Two Means (t)
Computes the confidence interval for the difference between the means of two independent groups, using the t distribution with pooled variances. It's the natural companion to the two-sample t-test: instead of only saying whether the difference is significant, it shows the plausible range for the real size of that difference. If the interval doesn't contain zero, there's a significant difference at the chosen level. Enter the two samples of values and the confidence level.
Two-Proportion z-Test
Computes the two-proportion z-test statistic, which compares the success rates of two independent groups — the backbone of any A/B test. For example: variant A converted 45 of 100 and B converted 30 of 100; is the difference real or noise? The statistic uses the pooled proportion of the two groups to estimate the standard error under the hypothesis that the proportions are equal. Enter the successes and the total of each of the two groups.
Z-Test for a Mean (Known σ)
Computes the z-test for a mean when the population standard deviation is known. It's the simplest case of hypothesis testing about a mean: the statistic measures how many standard errors separate the observed mean from the hypothesized value. When σ is known (or the sample is large), the normal distribution is used instead of the t. The tool returns the z statistic and the two-sided p-value. Enter the sample mean, the hypothesized mean, the population standard deviation and the sample size.
Kolmogorov-Smirnov Test (Two-Sample)
Computes the two-sample Kolmogorov-Smirnov test, which checks whether two samples come from the same distribution — without assuming what that distribution is. It compares the empirical cumulative distribution functions of the two samples and takes the largest vertical distance between them, the D statistic. Unlike the t-test, which only compares means, the KS test is sensitive to any difference in shape, spread or location. Enter the two samples of values.
Kolmogorov-Smirnov Test (vs Normal)
Computes the one-sample Kolmogorov-Smirnov test against a normal distribution with specified mean and standard deviation. It measures the largest vertical distance between your data's empirical cumulative distribution and the theoretical normal curve — the D statistic. Unlike tests that look only at skewness or kurtosis, the KS compares the entire distributions, point by point. Enter the sample and the normal parameters (mean and standard deviation) to test.
Spearman Correlation (ρ)
Compute Spearman rank correlation ρ between X and Y lists.
The results provided by this tool are for general informational and educational purposes only and do not constitute professional, financial, medical, legal, tax or accounting advice. Always confirm important decisions with a qualified professional and official sources.