According to the book I\'m reading, rand() requires #include in C++
However, I am able to compile the following code that uses
You definitely should use the relevant include file for what you are using in your code. It saves you from surprises when you update the compiler/libraries to the new version. I think adding std:: in front of rand is a much better idea than to use using namespace std; - but either way, it's a good idea to NOT rely on it existing without a namespace, although that tends to be the way it works in most places to allow backwards compatibility for C-code.