No, java's implementation of modulus will return a value in the range (-n, n)
for the value x % n
. I.e. If you have a negative number as the left operand, then the result will be negative. to get around this, try something like the following:
((x % n) + n) % n;
Which will return a value in the range [0,n)
EDIT (to reflect UPDATE in question)
In the case of positive numbers in the left operand, then simply x % n
will produce numbers in the range [0,n)
where x >= 0
.