When you're doing rand() % 6 + 1, it's like you're saying "Give me a random number, divide it by 6 and keep the remainder, then add 1 to it." This neat little trick is how you get a range of 1 to 6 instead of the full spectrum.
And you're right, % usually works with whole numbers, but the remainder can be a fraction if the divisor is greater than the dividend. This is where the magic of truncating comes in, giving you those whole...
Leave a comment: