0

Why is it not giving random number?

it only giving 41 as a result

8th May 2017, 6:46 PM
MNaveed Asim
MNaveed Asim - avatar
3 Antworten
+ 14
You need to randomise the seed for RNG algorithm. The most commonly used way is by using system time. #include <iostream> #include <cstdlib> #include <ctime> int main() { srand(time(0)); std::cout << rand(); return 0; }
9th May 2017, 12:16 AM
Hatsy Rei
Hatsy Rei - avatar
+ 10
because you didn't use srand(time(0));
8th May 2017, 9:52 PM
Umbe
Umbe - avatar