+ 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?
2 odpowiedzi
+ 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/
0
You can get random number everytime by setting seed like by using srand
srand(time(NULL)) ;