+ 1

What "is" rand() actually? It gives the same result everytime.

I don't think that rand() is really random. it gives the same result every time I run the code. What is the actual use of it then?

2nd May 2021, 5:43 AM
Anuj Kumar Patel
Anuj Kumar Patel - avatar
2 Respostas
+ 3
It gives the same result because the numbers generated by rand() aren't 'truly' random. See this: https://stackoverflow.com/questions/9459035/why-does-rand-yield-the-same-sequence-of-numbers-on-every-run It is also there in the SL C++ course (see section 4 of the link): https://www.sololearn.com/learning/1638/
2nd May 2021, 5:47 AM
XXX
XXX - avatar
0
You can get random number everytime by setting seed like by using srand srand(time(NULL)) ;
2nd May 2021, 6:03 AM
YUGRAJ