Why Rand() function gives same output?
The working of rand depends upon seed value of rand which is ‘srand()’. In many C libraries, if
srand()
is not called beforerand()
, the random number generator is automatically seeded with a default value (often 1).This means that without explicitly setting a seed using
srand()
, you’ll get the same sequence of random numbers every time you run your program. This behaviour is not ideal for scenarios where you want different random sequences on each program run.
Why Rand() function Always give the Same Value ?
Have you ever wondered why the rand() function always gives the same values each time we compile and run our code? well in this post we are going to discuss this phenomenon in brief.
First, let us discuss what is rand() function and what is its property.