+ 1
how Does srand() and rand() works?
i can't understand it how it works to generate ramdom numbers.
2 Answers
+ 2
the answer is complex in simple words it has process that changes set of values to obtain result use that result to give output it uses time as seed so random output is according to time
+ 1
in simple words rand() has a huge list of random numbers but each time we call it, the list is called in the same sequence, making it predictable. To make it truly random srand() is used. Every time you give srand() a different number as an argument, the rand() list will start from a different number. So we use the current time as an argument for srand(). Because time is continuously changing so the rand() list will also start every time from a different number and thus making it more random and unpredictable.