RNG Won't Initialize

I feel stupid right now cause I'm copying the exact code my prof posted and it won't work. It say's 'time' is not declared in the scope. Using codeblocks with G++11.
Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
    srand(time(NULL));  // set random number seed based on current time

    for(int i = 0; i < 10; ++i) {
        int r = rand();
        cout << r << "\n";
    }

    cout << "RAND_MAX = " << RAND_MAX << "\n";
} // main 
You need to #include <ctime> he probably can compile without it because some times compilers have built in libraries.



Oh and by the way it's a PRNG :P
Last edited on
Topic archived. No new replies allowed.