Quote:
Originally Posted by Matt L
Yes, you can use rand()%6 to get a number in the range of [0,5].
For any purists out there, I will note that as this uses only the low bits of the result of rand(), it is not very random. You should be using the high bits by dividing by RAND_MAX in floating-point, multiply by 6, then convert to an integer.
Also note that the modulus operator is well-defined on positive inputs only. That's not something to worry about with the return value of rand().
|
I could do RAND_MAX deal ... could..