Monte Carlo Simulator for Pi and Probability
Run up to a million random trials to estimate pi or a probability, watch the estimate settle on a convergence chart and compare it with the exact answer and its error.
ทำงานในเบราว์เซอร์ของคุณ ไฟล์ไม่ออกจากอุปกรณ์ ดูวิธีตรวจสอบ
…
วิธีทำ
- 1Choose an experiment
Pick π, Buffon's needle, birthday, Monty Hall, dice or cards in the Experiment menu.
- 2Set the details
Enter the number of people, dice, target total, cards or needle length that appear for that experiment.
- 3Choose the trials
Select 100 to 1,000,000 trials and keep or change the seed.
- 4Run and compare
Press Run and compare the estimate with the exact value, the error and the 95 % interval.
- 5Read the chart
Watch the running estimate settle towards the green exact line as trials increase.
- 6Review and practise
Compare earlier runs in Run history, export them as CSV and try the Practice questions.
เกี่ยวกับเครื่องมือนี้
The Monte Carlo method answers a question by simulating it many times with random numbers and counting what happens. It was named in the 1940s by Stanisław Ulam and John von Neumann, and today it is used in physics, finance, weather forecasting and computer graphics. For a student it is also the clearest way to see probability in action: you can guess an answer, run a hundred thousand trials in a second and check. This simulator offers six classic experiments. Two estimate π, one by throwing random points into a square and one with Buffon's needle; the others are the birthday problem, the Monty Hall game, the total of several dice and the chance of an ace in a hand of cards. Each run reports the estimate, the exact value, the error and a 95 per cent interval.
How the π experiment works
Choose random points (x, y) with both coordinates between 0 and 1. They fill a unit square evenly. The quarter circle x² + y² ≤ 1 covers π/4 of that square, so the share of points that land inside it is close to π/4. Multiply by four and you have an estimate of π. The picture next to the results shows the first 3 000 points coloured blue inside and red outside the arc.
Buffon's needle
In 1733 Georges-Louis Leclerc, Comte de Buffon, asked how likely a needle dropped on a floor of parallel boards is to cross a gap. For a needle of length l and boards of width t with l no longer than t, the answer is 2l ÷ (πt). Counting crossings in many drops therefore gives π ≈ 2l × drops ÷ (t × crossings). It converges more slowly than the square method, which the convergence chart makes visible.
The probability experiments
The birthday problem asks how likely it is that at least two people in a group share a birthday. The exact answer for 23 people is 50.7 per cent, far higher than most people guess. In the Monty Hall game you pick one of three doors, the host opens another door with a goat, and you switch: you win the car two times in three because switching wins whenever your first pick was wrong. The dice experiment counts how often several dice reach a chosen total, and the card experiment counts hands with at least one ace. For each one the tool shows the exact probability worked out with the matching formula.
Error, sample size and seeds
A Monte Carlo estimate wobbles. Its standard error shrinks in proportion to 1/√N, so a hundred times more trials only gives about ten times more accuracy. The tool reports the standard error and a 95 per cent interval, plots the running estimate on a logarithmic sample scale, and keeps a history of runs so you can compare 1 000, 10 000 and a million trials. A seed makes runs repeatable: the same seed always produces the same random numbers, which is useful for a class demonstration.
Worked example
With 23 people and 20 000 simulated groups, a typical run finds a shared birthday in about 10 150 groups, an estimate of 0.507. The exact value is 1 − (365 × 364 × … × 343) ÷ 365²³ = 0.5073, so the error is a fraction of a percentage point and the 95 per cent interval of roughly ±0.007 includes the true value.
Limits
The random numbers come from a fast seeded generator suitable for teaching, not for cryptography or published research. Real birthdays are not spread perfectly evenly through the year, and the card and dice models assume fair, well-shuffled equipment. Very large runs can take a few seconds on older phones.
ตัวอย่างพร้อมวิธีทำ
23 people, 20 000 trials: estimate ≈ 0.507 against the exact 0.5073; 100 000 points give π ≈ 3.14 ± 0.01.
สรุปสั้น ๆ
- หมวดหมู่: คณิตศาสตร์และวิทยาศาสตร์
- ทำงานในเบราว์เซอร์ ไม่ต้องสมัคร ไม่ต้องอัปโหลด
- ข้อมูลที่คุณกรอกอยู่บนอุปกรณ์ของคุณ
- มีภาษาอังกฤษ
- ตรวจสอบเนื้อหาล่าสุด:
- แหล่งข้อมูลทางการ: Grinstead and Snell, Introduction to Probability (American Mathematical Society), chapters 1 and 2
คำถามที่พบบ่อย
Why does multiplying by 4 give π?
The quarter circle has area π/4 and the square has area 1, so the share of random points inside the quarter circle is about π/4.
How many trials do I need for two correct decimal places of π?
The standard error with N points is about 1.64 ÷ √N, so around 100 000 points usually give 3.14, and a million points usually give the third decimal.
Is switching really better in the Monty Hall game?
Yes. Run the experiment: switching wins about 66.7 per cent of the time, because it wins exactly when your first choice was a goat.
What does the seed do?
It fixes the sequence of random numbers, so the same seed and settings reproduce the same run. Use a new seed to see a different sample.
Why is Buffon's needle less accurate?
Each drop gives less information than a random point, so the estimate of π wobbles more for the same number of trials.
Does the tool upload anything?
No. Every trial runs in your browser and the run history is stored only on this device.
