Jul 10, 2012 at 4:42am UTC
Hello,
I am trying to seed time() into srand(), in order to calculate a rand() number with a predefined parameter, in this way:
srand(time());
randomNum = 1 + rand() %10;
The above code should work, but it isn't the compiler (Visual Studio 2010) is complaining about he "srand(time());" part,
If anybody could help me make sense of this I wold greatly appreciated.
P.S. I did include the <ctime> header file idk if there is another header file to be included.
Jul 10, 2012 at 4:47am UTC
but it isn't the compiler (Visual Studio 2010) is complaining about he "srand(time());" part,
For future reference, post the error message. The thing about error messages is they tend to tell you exactly what's wrong.
Anyway, time takes a parameter and you aren't giving it any:
EDIT: ninja'd
NULL and 0 are equivalent, assuming you have NULL defined (which you may not)
or if you have C++11 capabilities, you can use
nullptr
instead.
Last edited on Jul 10, 2012 at 4:48am UTC