Someone please correct me if I'm wrong, but I see a couple of problems here.
First, rand() and srand() are functions defined in stdlib.h. Are you trying to implement your own versions of these functions? Second problem I see is you are declaring your function prototypes inside of main():
Code:
#include <stdio.h>
int main()
{
int rand(void);
void srand(unsigned int);
...........
}
They should be defined outside of the main() loop like:
Code:
#include <stdio.h>
int rand(void);
void srand(unsigned int);
int main(void) {
.......
}
Also you should use "void" as the argument to main() if you aren't going to pass any command line arguments, as in the example I provided earlier. Now, onto your original question. The value of next is being assigned the difference of the result of the expression:
Code:
next = next * 1103515245 + 12345; //which is 5517588570
and the size of the data type (unsigned long int):
Code:
5517588570 - 4294967296 = 1222621274
The reason next is being assigned 1222621274 is because of two's complement, if I'm not mistaken.
1222621274 is is then divided by 65536, which gives the answer of 18655. Since you are typecasting the return value as an int, and the result of the modulus division is less than 1, it ignores everything after the whole number 18655.
Hope this helps