How does the rand() function in C programming language work? Why does it generate a new(random) output everytime?
rand() function takes no parameter and returns a random number(integer) in the range 0 to RAND_MAX.
The value of RAND_MAX is defined in stdlib.h header file and is 32767.
int rand(void); //prototype of rand()
It uses a generator of the form
X(0) is the seed.
m is modulus(which is 32768 in this case)
a & c are integers(generally long positive integers)
Based on different values of the seed, different random sequences can be generated.