00001
00002
00003
00004
00005
00006
00007
00008 #include <fstream>
00009 #include <cstdio>
00010 #include <cstdlib>
00011 #include <iostream>
00012
00020 std::string generateRandomString(int length);
00021
00022 using namespace std;
00023
00024 int main(int argc, char** argv) {
00025
00026 if (argc != 7) {
00027 std::cout << "Usage: ./KeyValueGenerator fileName, reqCount, minKeyLength, maxKeyLength, minObjectSize, "
00028 "maxObjectSize" << std::endl;
00029 return 1;
00030 }
00031
00032 string fileName = argv[1];
00033 int count = atoi(argv[2]);
00034 int minKeyLength = atoi(argv[3]);
00035 int maxKeyLength = atoi(argv[4]);
00036 int minObjectSize = atoi(argv[5]);
00037 int maxObjectSize = atoi(argv[6]);
00038
00039 ofstream output;
00040 output.open(fileName.c_str(), ios::out | ios::binary);
00041 output.write((char*) &count, sizeof(count));
00042 for (int i = 0; i < count; i++) {
00043
00044 int keyLength = minKeyLength + rand() % (maxKeyLength - minKeyLength + 1);
00045 int valueLength = minObjectSize + rand() % (maxObjectSize - minObjectSize + 1);
00046
00047 string key = generateRandomString(keyLength);
00048 string value = generateRandomString(valueLength);
00049
00050 output.write((char*) &keyLength, sizeof(keyLength));
00051 output.write((char*) &valueLength, sizeof(valueLength));
00052 output.write((char*) key.c_str(), keyLength);
00053 output.write((char*) value.c_str(), valueLength);
00054 }
00055
00056 return 0;
00057 }
00058
00059 std::string generateRandomString(int length) {
00060 std::string output;
00061 for (int i = 0; i < length; i++)
00062 output += (char) ('a' + rand() % 26);
00063 return output;
00064 }
00065