Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created October 29, 2015 21:09
Show Gist options
  • Select an option

  • Save TheBuzzSaw/c49969cde57fec5e05ae to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/c49969cde57fec5e05ae to your computer and use it in GitHub Desktop.
Math Truth!
#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