Created
October 29, 2015 21:09
-
-
Save TheBuzzSaw/c49969cde57fec5e05ae to your computer and use it in GitHub Desktop.
Math Truth!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <random> | |
| #include <sstream> | |
| using namespace std; | |
| void RollDice(mt19937_64& mt, int n) | |
| { | |
| uniform_int_distribution<int> distribution(1, 30); | |
| int matchCount = 0; | |
| for (int i = 0; i < n; ++i) | |
| { | |
| int a = distribution(mt); | |
| int b = distribution(mt); | |
| matchCount += a == b; | |
| } | |
| cout << matchCount << " matches out of " << n << " random pairs" << endl; | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| mt19937_64 mt; | |
| for (int i = 1; i < argc; ++i) | |
| { | |
| stringstream ss; | |
| ss << argv[i]; | |
| int n; | |
| if (ss >> n) RollDice(mt, n); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment