hey all, been a while (damn jobs)
so im familiar with the rand() function, and how to get a random number within a certain range, but as i was flipping through one of my books i noticed its telling me that i need to include <cstdlib> in order to call the rand() function.. however I ran the following code without it and got the same (random) results...
im just curious about how this is happening. Is it simply good practice to include <cstdlib> or was there some kind of C++ update that allows the rand() function to be called without it? not of uttermost importance, just curious
this code runs fine for me and still generates random numbers from 1 - 6...Code:#include<iostream> #include <ctime> using namespace std; int main() { srand(time(0)); for (int i = 0; i < 15; i++) { int randomNumber= (rand() % 6) + 1; cout<< randomNumber << endl; } system("pause"); }



4Likes
LinkBack URL
About LinkBacks




So tell us Zuk,why did not the compiler complained?Neither to me or to Mike? I can not figure out