Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include <fstream>
- #include <vector>
- #include <string>
- #include <ctime>
- #define USERS 1000000
- #define PRODUCTS 500000
- #define FRIENDS_BY_USER 20
- #define PRODUCTS_BY_USER 5
- const std::vector<std::string> P_NAME = {
- "peakers",
- "fridge",
- "shampoo",
- "sun glasses",
- "house",
- "cat",
- "cookie jar",
- "puddle",
- "sofa",
- "lotion",
- "playing card",
- "stockings",
- "packing peanuts",
- "CD",
- "flowers",
- "wallet",
- "soda can",
- "key chain",
- "pillow",
- "buckel",
- };
- const std::vector<std::string> NAMES = {
- "Metheny",
- "Christofferse",
- "Hester",
- "Sugrue",
- "Seawood",
- "Raper",
- "Brakebill",
- "Hotaling",
- "Arcand",
- "Teaster",
- "Lovings",
- "Paugh",
- "Smelley",
- "Pegg",
- "Bratton",
- "Tilly",
- "Axelrod",
- "Madry",
- "Wiegand",
- "Strawser"
- };
- template<typename T>
- T randomElement(const std::vector<T> &from)
- {
- return from[std::rand() % from.size()];
- }
- std::string randomProduct()
- {
- return randomElement(P_NAME);
- }
- std::string randomName()
- {
- return randomElement(NAMES);
- }
- std::string uuid()
- {
- static const std::string CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- std::string uuid = std::string(36,' ');
- int rnd = 0;
- uuid[8] = '-';
- uuid[13] = '-';
- uuid[18] = '-';
- uuid[23] = '-';
- uuid[14] = '4';
- for(std::size_t i=0;i<36;i++){
- if (i != 8 && i != 13 && i != 18 && i != 14 && i != 23) {
- if (rnd <= 0x02) {
- rnd = (0x2000000 + (std::rand() * 0x1000000)) | 0;
- }
- rnd >>= 4;
- uuid[i] = CHARS[(i == 19) ? ((rnd & 0xf) & 0x3) | 0x8 : rnd & 0xf];
- }
- }
- return uuid;
- }
- int main()
- {
- std::srand(std::time(0));
- std::ofstream friendFiles("users.csv");
- std::vector<std::string> userList;
- std::vector<std::string> productList;
- userList.reserve(USERS);
- productList.reserve(PRODUCTS);
- for(int i = 0; i < USERS; ++i){
- std::string id = uuid();
- std::string name = randomName();
- userList.push_back(id);
- friendFiles << id << "," << name << "\n";
- }
- friendFiles.close();
- std::ofstream productFiles("products.csv");
- for(int i = 0; i < PRODUCTS; ++i){
- std::string id = uuid();
- std::string name = randomProduct();
- productList.push_back(id);
- productFiles << id << "," << name << "\n";
- }
- productFiles.close();
- std::ofstream friendsFile("friends.csv");
- for(const std::string &id : userList){
- for(int i = 0; i < 1 + std::rand() % FRIENDS_BY_USER; ++i){
- std::string friendWith = randomElement(userList);
- if(id == friendWith) continue;
- friendsFile << id << "," << friendWith << "\n";
- }
- }
- friendsFile.close();
- std::ofstream productBuy("buy.csv");
- for(const std::string &id : userList){
- for(int i = 0; i < 1 + std::rand() % PRODUCTS_BY_USER; ++i){
- std::string buying = randomElement(productList);
- productBuy << id << "," << buying << "\n";
- }
- }
- productBuy.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement