// Problem 3: Normal Distribution (Box-Muller)
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(time(0));
int N = 20000;
double sum = 0, sumSq = 0;
int pairs = N / 2;
cout << "Generating " << N << " normal random values...\n";
for (int i = 0; i < pairs; i++) {
double u1 = (rand() + 1.0) / (RAND_MAX + 1.0);
double u2 = (rand() + 1.0) / (RAND_MAX + 1.0);
double z0 = sqrt(-2.0 * log(u1)) * cos(2 * M_PI * u2);
double z1 = sqrt(-2.0 * log(u1)) * sin(2 * M_PI * u2);
sum += z0 + z1;
sumSq += z0 * z0 + z1 * z1;
}
double mean = sum / N;
double variance = (sumSq / N) - mean * mean;
double stddev = sqrt(variance);
cout << "\nStatistics:\n";
cout << "Mean : " << mean << endl;
cout << "StdDev : " << stddev << endl;
return 0;
}
/*
Q1. Does your distribution resemble a bell curve?
= Yes. The generated numbers follow a bell-shaped (Normal) distribution.
Q2. What is the mean and stddev? Are they close to 0 and 1?
= Mean is approximately 0 and StdDev approximately 1. Randomness causes slight variations,
but repeated runs confirm they stay near 0 and 1.
*/