C ++ random numbers

How to use random numbers in Linux and C ++?

I found code that I would like to use, it has a line

srand((unsigned)time(0));//seed

but gcc says

board.cpp: 94: 24: error: "time has not been announced in this area

I have included the following files

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
+5
source share
4 answers

You did not include a header that defines the function, so that your program can know how to call the time () you need to add:

#include <time.h>

and just for nitpick (code style) your call should be more correct (NULL) instead of time (0)

+9
source

You will need

#include <ctime>

to access the function time.

+13
source

<time.h>

+4
+2
source

All Articles