Below is the code that I'm playing around, I'm just trying to figure out on how does the Random number generator works in C++ it's really weird...
PHP Code:
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
#include <string>
using std::endl;
using std::string;
#include <iomanip>
using std::setw;
#include <cstdlib>
using std::rand;
int main() {
for (int i = 0; i < 10; i++) {
cout << setw(10) << ( 1 + rand() % 6 ) << endl;
}
return 0;
}
More precisely this part:
PHP Code:
( 1 + rand() % 6 )
I tried to remove the 1, however I think it gives me from 0 to 5, why do we have to do modulus 6? How does it works?