I need to generate a large number of random alphanumeric string, it is okay with the size below 10000, but when I tried to create the size 100,000, it returned the error -1073741571 (0xC00000FD) and my code won't run. Please tell me what is the error and how to solve it.
Below are my codes:
#include <iostream>
#include <ctime>
#include <unistd.h>
using namespace std;
string gen_random(const int len) {
string tmp_s;
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
srand(rand() ^ (unsigned) time(NULL) * getpid());
tmp_s.reserve(len);
for (int i = 0; i < len; ++i)
tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
return tmp_s;
}
bool repeat(string target, string arr[],int arr_size)
{
for (int i=0; i<arr_size; i++)
{
if (arr[i].compare(target) == 0)
return true;
}
return false;
}
int main(int argc, char *argv[])
{
const int n = 100000;
string data_set[n];
for (int i=0; i<n; i++)
{
string s = gen_random(4) + "." + gen_random(5) + "@" + gen_random(5);
if (!repeat(s,data_set,n))
data_set[i] = s;
else
i--;
}
for (int i=0; i<n; i++)
cout << data_set[i] << endl;
return 0;
}