+ 1
Is there any relation between the number given to srand() function and the generated ramdom numbers as output?
Please give the relation
1 ответ
+ 3
The basic rule for initializing srand(x) function is that in every program run, the function needs to get a completely distinctive value x as argument BEFORE using rand() function. As you probably aware, the time() function returns the operating system's current time (in terms of second). The nature of time makes it possible to achieve a satisfactory distinctive value. (for programs or routines that runs more than once in a second, that produce the same output which is undesirable)
So, if you happen to give x in srand(x) a constant value, rand() guarantees to produce the same values for each program execution.