Hi Guys!
So, I am using the modulus and a rand as part of a function I am writing. Now, I understand that:
gives me a random number between one and six in this situation. However, I also know that
gives me a random value from 0 - 32767 and
changes the sequence
but I thought...
% = Whatever the remainder of a is after a / b.
... So, if you were to break
up, what would it look like?
I need to make sense of this for my own good because I look at
like this:
some random number / 6 = remainder left over from the random. Then add the one.
So, my question is two fold:
1 - how does
get restricted to just 1 - 5 all of a sudden instead of the spectrum of numbers from 0 - 32767?
2 - Any of those numbers (1-5) divided by 6 gives you a fractional number, not a whole one and I thought modulus only works with whole numbers. What info am I missing here?
As you can see I am confused about this. Help is always appreciated :)
So, I am using the modulus and a rand as part of a function I am writing. Now, I understand that:
Code:
rand() % 6 + 1;
Code:
rand();
Code:
srand;
but I thought...
% = Whatever the remainder of a is after a / b.
... So, if you were to break
Code:
rand() % 6 + 1;
I need to make sense of this for my own good because I look at
Code:
rand() % 6 + 1;
some random number / 6 = remainder left over from the random. Then add the one.
So, my question is two fold:
1 - how does
Code:
rand()
2 - Any of those numbers (1-5) divided by 6 gives you a fractional number, not a whole one and I thought modulus only works with whole numbers. What info am I missing here?
As you can see I am confused about this. Help is always appreciated :)
Comment