It seems unlikely, but the execution of some tests, after srand, the first rand seems to always be divisible by 7, at least in an int-sized variable.
On several runs, I got 1303562743, 2119476443 and 2120232758, all of which are from 7 to 0.
The second rand() works because it is the second rand() . Throw rand() to your first rand() ... or better yet, use the best random or arc4rand random number arc4rand , if available.
Also see the stack overflow question. Why (rand ()% anything) is always 0 in C ++? .
Grady Player Oct 23 '11 at 15:41 2011-10-23 15:41
source share