Created
July 3, 2018 02:37
-
-
Save sleepdefic1t/19fa107d4f2f57107c812e3216b8ce2b to your computer and use it in GitHub Desktop.
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> | |
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