Skip to content

Instantly share code, notes, and snippets.

@sleepdefic1t
Created July 3, 2018 02:37
Show Gist options
  • Save sleepdefic1t/19fa107d4f2f57107c812e3216b8ce2b to your computer and use it in GitHub Desktop.
Save sleepdefic1t/19fa107d4f2f57107c812e3216b8ce2b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <random>
int rand01()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 1);
return dis(gen);
}
int main()
{
int zeroCount = 0;
int oneCount = 0;
for (int i = 0; i < 1000; i++)
{
int randBit = rand01();
if (randBit == 0) { zeroCount++; }
else { oneCount++; }
}
std::cout << zeroCount << std::endl;
std::cout << oneCount << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment