This is probably a stupid question, but I'm really struggling with this concept. I am reading a tutorial on arrays and the rand () function. I have two problems.
First, obviously, to simulate a single bone, we need to randomly generate a number from 1-6. The book offers the following:
int RollOne( void ) {
return (rand() % 6) + 1;
}
Right, well rand () can generate any number from 0-32767. Then we find the remainder of this number when it divides by 6, then add 1. For example. 3245 is randomly generated. We divide it by 6, giving 540.8333 and take the remainder. 8.333 (truncated to 8, I believe), and then add 1. If I don't lose my mind, this is 9, which is not between 1-6. The program works fine, but I just canβt understand how we get a number from 1-6 using this code! Any help would be greatly appreciated.
The second problem that I have is actually not so important, but relevant. The book does not indicate what this bit of code means:
srand( clock() );
, , , srand() , , clock(). , - clock(), , ? , srand (clock()), .
, , wall'o'text. .
,
Mike
ANSWERED
: , . , , % , . ! , . 7/2 = 3,5, 0,5. , , , . , A -.....
!