+ 1
How it's random if it generates the same numbers each time i run the function??
i need an answer plz How it's random if it generates the same numbers each time i run the function??
4 odpowiedzi
+ 8
add srand(time(0)); to the start of main function
and you also need to add #include <ctime>
+ 6
You need a random function based on time. Set a seed based on the current time to generate a random number based off of a different seed every time.
+ 3
because, the rand() function is not truly random. if u want to generate truly random number I suggest you use srand(time(0)); and don't forget to include <ctime>
+ 2
like they mentioned above, you can use srand(time(0)).
in addtion , if you use visual studio as your compiler,you can use srand(time(nullptr)) as well.