I'm new to C. I just came across the rand() function. The book states that using rand() returns a random number from 0 to 32767. It also states that you can narrow the random numbers by using % (modulus operator) to do so. Here is an example: the following expression puts a random number from 1 to 6 in the variable dice
dice = (rand() % 6) + 1;
I’m wondering why you can’t use
dice = (rand() % 7);
Won’t it do the same thing?