Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Created January 23, 2019 20:50
Show Gist options
  • Save lnrsoft/fa536bf80284040f6184921615f0f0b9 to your computer and use it in GitHub Desktop.
Save lnrsoft/fa536bf80284040f6184921615f0f0b9 to your computer and use it in GitHub Desktop.
Roll a 6-sided die 5 times using c++
#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