-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomtext.cpp
More file actions
51 lines (40 loc) · 1.01 KB
/
randomtext.cpp
File metadata and controls
51 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
// Function to generate a random string of given length using printable ASCII characters
string random_string(int length)
{
static const char printable_chars[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"jklmnopqrstuvwxyz"
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
//without abcdefghi
string result(length, ' ');
srand(time(nullptr)); // seed the random number generator
for (int i = 0; i < length; i++) {
result[i] = printable_chars[rand() % (sizeof(printable_chars) - 1)];
}
return result;
}
int main()
{
int length = 10000;
string randomStr = random_string(length);
char c = 'a';
for(int index = 9000; index < 9005; index++)
{
randomStr[index] = c;
++c;
}
c = 'a';
for(int index = 9005; index < 9015; index++)
{
randomStr[index] = c;
++c;
}
cout << randomStr << endl;
return 0;
}