| 5 | #include "ctrack.hpp" |
| 6 | |
| 7 | double estimate_pi(int points) { |
| 8 | CTRACK; |
| 9 | std::random_device rd; |
| 10 | std::mt19937 gen(rd()); |
| 11 | std::uniform_real_distribution<> dis(-1.0, 1.0); |
| 12 | |
| 13 | int inside_circle = 0; |
| 14 | for (int i = 0; i < points; ++i) { |
| 15 | double x = dis(gen); |
| 16 | double y = dis(gen); |
| 17 | if (x*x + y*y <= 1.0) { |
| 18 | inside_circle++; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | return 4.0 * inside_circle / points; |
| 23 | } |
| 24 | |
| 25 | void run_estimations(int iterations, int points_per_estimation) { |
| 26 | for (int i = 0; i < iterations; ++i) { |