Created
January 23, 2019 20:50
-
-
Save lnrsoft/fa536bf80284040f6184921615f0f0b9 to your computer and use it in GitHub Desktop.
Roll a 6-sided die 5 times using c++
This file contains 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 <cstdlib> | |
#include <iostream> | |
#include <ctime> | |
int main() | |
{ | |
std::srand(std::time(nullptr)); | |
int random_variable = std::rand(); | |
std::cout << "Random value on [0 " << RAND_MAX << "]: " | |
<< random_variable << '\n'; | |
for (int n=0; n != 5; ++n) { | |
int x = 7; | |
while(x > 6) | |
x = 1 + std::rand()/((RAND_MAX + 1u)/6); | |
std::cout << x << '\n'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment