+ 1

Is there any relation between the number given to srand() function and the generated ramdom numbers as output?

Please give the relation

6th Jun 2018, 3:15 AM
Rounak Sartaliya
Rounak Sartaliya - avatar
1 Odpowiedź
+ 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.
6th Jun 2018, 6:59 AM
Babak
Babak - avatar