#include #include using namespace std; float x, y; int sed; double pizzle; int inside = 0; const int TRIALS = 60000; const int lolwut = 50000; float current = 0.00122525; int main (int argc, char * const argv[]) { cout << "Estimating pi with " << lolwut << " different seeds..." << endl; for (int j = 0; j < lolwut; j++) { // Not really in code, checking for seed that gets closest to pi inside = 0; srand(j); // Closest: 11 at 3.14048 for (int i = 0; i < TRIALS; i++) { // Generate x and y where 0 < x < 1 and 0 < y < 1 x = double(rand()) / (ULONG_MAX / 2 - 1); y = double(rand()) / (ULONG_MAX / 2 - 1); // Check if it's inside the quarter-circle if ((x * x) + (y * y) <= 1) inside++; } float pi = 4.0 * double(inside) / double(TRIALS); if (3.14159265358979 - pi > current) { current = 3.14159265358979 - pi; sed = j; pizzle = pi; cout << "New closest to pi, seed " << sed << " where pi = " << pi << endl; } } cout << "Use seed " << sed << " to get pi = " << pizzle << " with a difference of " << current << endl; return 0; }