0

#include <iostream> #include <cstdlib> using namespace std; int main() { cout << rand(); } output = 41 Why this code code gi

30th Apr 2017, 9:56 AM
urvi
3 Antworten
+ 15
@Jay is correct. You need to randomise your seed for RNG. One of the most common ways is to use system time. #include <iostream> #include <cstdlib> #include <ctime> int main() { srand(time(0)); std::cout << rand(); return 0; }
30th Apr 2017, 11:15 AM
Hatsy Rei
Hatsy Rei - avatar
30th Apr 2017, 10:02 AM
Meharban Singh
Meharban Singh - avatar
+ 7
you need to seed?
30th Apr 2017, 10:09 AM
jay
jay - avatar