Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <random>
- #include <iostream>
- std::random_device rd;
- std::uniform_int_distribution<int> distribution(0, 1);
- std::mt19937 engine(rd()); // Mersenne twister MT19937
- bool coin ()
- {
- return distribution (engine);
- }
- int main ()
- {
- int a = 1000;
- int b = 0;
- for (int i = 0; i < a; ++i)
- b += (coin () ? 1 : 0);
- std :: cout << "Verify coin(): " << b << "/" << a << "\n\n";
- for (long int TRIALS = 10; TRIALS < 1000000000000; TRIALS *= 10)
- {
- long double winnings = 0;
- for (int i = 0; i < TRIALS; ++i)
- {
- long double pot = 2;
- if (! coin ())
- continue;
- while (true)
- {
- if (! coin ())
- break;
- pot *= 2;
- }
- // std :: cout << "Won $" << pot << "\n";
- winnings += pot;
- }
- std :: cout << TRIALS << ",\t" << (winnings / TRIALS) << "\n"
- << std :: flush;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement