Hi.
First: I'm quite a complete newbie when it comes to C/C++. but not programming in general. I've never written any very large programs, but I've dabbled around in a dozen or so languages. I can usually figure out the logic, but in any new language, I need to learn the syntax :)
So, I'm currently using the newest (as of 2013-03-19) Code::Blocks, with built-in GNU compiler (I believe that was MinGW).
I have a bit of a problem with random numbers. I just need a very simple semi-random number for a die roller test.
But this.
1 2 3 4 5 6
|
int main() {
int diceroll = (rand() % 6) + 1;
std::cout << diceroll;
return 0;
}
|
This is making me lose my hair. I believe that is supposed to give me a semi-random spread of numbers between 1 and 6, right? Well, at least on my computer, with my environment, it doesn't. I regularly get result ranging from 0 to 7. If I omit the +1, I get results ranging from -1 to 6. I don't get it. I really don't.
What am I doing wrong? Or have I configured my environment somehow wrong? Or does Code::Blocks/MinGW have an issue with rand()?
I'm using Win7 x64, if that matters.