Newer
Older
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
#include <iostream>
#include <string>
#include <fstream>
#include "random_string.h"
#include "random_int.h"
int main(){
// The random string generator
rand_string a;
// A random generator to decide when to duplicate the string
rand_int b{0,100};
const int DUP_PROB=30;
// An output file
std::ofstream f;
std::string name;
std::cout << " Enter the file name: ";
std::cin>>name;
f.open(name.c_str());
if(!f) {
std::cout <<"Error in opening file: " << name << std::endl;
return 1;
};
std::cout << " File opened: " << name << std::endl;
int maxs{500},duplicates{0};
std::cout << " Enter the number of random string to be generated: ";
std::cin>>maxs;
for(int i=0; i<maxs; ++i) {
std::string t{a()};
f<<t <<'\n';
// Duplicate 30% of the strings
if(b()<=DUP_PROB) {
f<<t<<'\n';
++duplicates;
}
}
f.close();
std::cout<< maxs <<" random strings generated and saved into file: " << name <<". " << duplicates << " duplicates generated." << std::endl;
return 0;
}