Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shikamaru

Member Since 26 Apr 2009
Offline Last Active Oct 28 2012 03:41 PM
-----

#4959330 Need help understanding this logic....

Posted by Shikamaru on 15 July 2012 - 12:51 PM

Ok so I'm reading the book, Beginning C++ Through Game Programming, and i'm having trouble understanding a paragraph. I know what the code does what I cant seem to understand is how the author comes to the conclusion here is the paragraph"

"after generating a random number, randomNumber now holds a value between 0 and 32,747. But I need a number between 1 and 6, so next I use the modulus operator to produce a number in that range

int die = (randonNumber % 6) + 1;   // I know how this works.

any positive number divided by 6 will give a remainder between 0 and 5"

That last line is where i get confused... for instance lets say the value in randomNumber is 22,465 that divided by 6 is going to be between 0 and 5. my result is remainder one so that works but what happens if the value of randomNumber is 32,747 the remainder would be 8. My math could be off. So my question is, can the value never be the max? mostly every other number would produce the right remainder but not the max number. I think I understand but I just need some more info to help explain this. another thing im not quite clear on is 6 goes into 10 once with the remainder 4 so how does the value 5 come into play? if anyone can clear this up for me I'd be very grateful...


PARTNERS