I am trying to write a program that generate 5 million different random numbers in C++. Below is the code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main() {
unsigned before = clock();
srand(time(NULL));
long numbers[5000000];
for (int i = 0; i < 5000000; i++)
numbers[i] = rand() % 5000000;
for (int i = 0; i < 5; i++)
cout<<numbers[i]<<endl;
cout<<clock() - before<<endl;
return 0;
}
Every time I run it, nothing happens and the program crashes on me. I can't seem to find what I'm doing wrong since the code is so simply. Can someone please help me? Thank you.