Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <chrono>
- using namespace std::chrono;
- double Random()
- {
- static const unsigned int A = 1686629717;
- static const unsigned int C = 907633385;
- static unsigned int n = time(nullptr);
- return static_cast<double>(n = A * n + C) / 0xFFFFFFFF;
- }
- double pi(int N)
- {
- int M = 0;
- double x = -1, y = -1;
- for (int i = 0; i < N; ++i)
- {
- x = Random();
- y = Random();
- if (x * x + y * y <= 1)
- ++M;
- }
- return M * 4.0 / N;
- }
- int main()
- {
- double N = 0;
- printf_s("count: ");
- scanf_s("%lf", &N);
- auto s = high_resolution_clock::now();
- auto p = pi(N);
- auto t = duration_cast<duration<double, std::ratio<1>>> (high_resolution_clock::now() - s).count();
- printf_s("pi: %lf; time: %lf s\n", p, t);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement