Because if rand() return 98 , then 98 % 99 is 98 and 98 + 11 > 99 .
For this you need
i2 = 11 + ( rand() % 89 );
rand() % 89 will give you the numbers [0, 88] , so +11 will become [11, 99] .
By the way, do not forget srand( time( NULL ) ) , otherwise it (most likely) will generate the same sequence of (pseudo) random numbers all the time.
source share