Reputation: 61
How can I use random numbers in Linux and C++?
I have found some code I would like to use, it has the line
srand((unsigned)time(0));//seed
but gcc says
board.cpp:94:24: error: ‘time’ was not declared in this scope
I have included the following files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
Upvotes: 5
Views: 19243
Reputation: 16142
You haven't included the header that defines the function, in order for your program to know how to call time() you need to add this include:
#include <time.h>
and just to nitpick (code style) your call should more correctly be time(NULL) instead of time(0)
Upvotes: 10
Reputation: 89
Indeed, It misses the include for the time function try :
#include <time.h>
you can go there to have a little more explanation about srand:
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
Upvotes: 2