Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ random numbers

Tags:

c++

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>
like image 476
Cppnoobie Avatar asked Jun 15 '11 15:06

Cppnoobie


Video Answer


1 Answers

You'll need

#include <ctime>

to access the time function.

like image 105
SolarBear Avatar answered Sep 30 '22 15:09

SolarBear