-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandCreat.cpp
More file actions
58 lines (46 loc) · 920 Bytes
/
RandCreat.cpp
File metadata and controls
58 lines (46 loc) · 920 Bytes
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
52
53
54
55
56
57
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <stdlib.h>
#include <ctime>
using namespace std;
const int Amount = 100000;
//const double rate =0.666;
void RandCreat(const char *address)
{
srand((unsigned)time(NULL));
set<string> names;
//FILE *fp = NULL;
//errno_t err = fopen_s(&fp, address, "w");
//if ( err!= 0) return;
FILE *fp=fopen(address,"w");
if (fp==NULL) return ;
int nowsize = 0;
while (nowsize<Amount)
{
int len = 5 + rand() % 5;
string name = "";
for (int i = 0; i<len; ++i)
{
if (rand() % 2) name += rand() % 26 + 'a';
else name += rand() % 26 + 'A';
}
if (names.find(name) == names.end())
{
names.insert(name);
fprintf(fp, "%s\n", name.c_str());
nowsize++;
}
}
fprintf(fp, "0");
fclose(fp);
}
int main(int argc, char *argv[])
{
//RandCreat("input.txt");
for (int i = 1; i < argc; ++i)
{
RandCreat(argv[i]);
}
return 0;
}