Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. //main.cpp
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <ctime>
  6.  
  7. #define USERS 1000000
  8. #define PRODUCTS 500000
  9. #define FRIENDS_BY_USER 20
  10. #define PRODUCTS_BY_USER 5
  11.  
  12. const std::vector<std::string> P_NAME = {
  13. "peakers",
  14. "fridge",
  15. "shampoo",
  16. "sun glasses",
  17. "house",
  18. "cat",
  19. "cookie jar",
  20. "puddle",
  21. "sofa",
  22. "lotion",
  23. "playing card",
  24. "stockings",
  25. "packing peanuts",
  26. "CD",
  27. "flowers",
  28. "wallet",
  29. "soda can",
  30. "key chain",
  31. "pillow",
  32. "buckel",
  33. };
  34.  
  35. const std::vector<std::string> NAMES = {
  36. "Metheny",
  37. "Christofferse",
  38. "Hester",
  39. "Sugrue",
  40. "Seawood",
  41. "Raper",
  42. "Brakebill",
  43. "Hotaling",
  44. "Arcand",
  45. "Teaster",
  46. "Lovings",
  47. "Paugh",
  48. "Smelley",
  49. "Pegg",
  50. "Bratton",
  51. "Tilly",
  52. "Axelrod",
  53. "Madry",
  54. "Wiegand",
  55. "Strawser"
  56. };
  57.  
  58. template<typename T>
  59. T randomElement(const std::vector<T> &from)
  60. {
  61. return from[std::rand() % from.size()];
  62. }
  63.  
  64. std::string randomProduct()
  65. {
  66. return randomElement(P_NAME);
  67. }
  68.  
  69. std::string randomName()
  70. {
  71. return randomElement(NAMES);
  72. }
  73.  
  74. std::string uuid()
  75. {
  76. static const std::string CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  77. std::string uuid = std::string(36,' ');
  78. int rnd = 0;
  79.  
  80. uuid[8] = '-';
  81. uuid[13] = '-';
  82. uuid[18] = '-';
  83. uuid[23] = '-';
  84.  
  85. uuid[14] = '4';
  86.  
  87. for(std::size_t i=0;i<36;i++){
  88. if (i != 8 && i != 13 && i != 18 && i != 14 && i != 23) {
  89. if (rnd <= 0x02) {
  90. rnd = (0x2000000 + (std::rand() * 0x1000000)) | 0;
  91. }
  92. rnd >>= 4;
  93. uuid[i] = CHARS[(i == 19) ? ((rnd & 0xf) & 0x3) | 0x8 : rnd & 0xf];
  94. }
  95. }
  96. return uuid;
  97. }
  98.  
  99. int main()
  100. {
  101. std::srand(std::time(0));
  102. std::ofstream friendFiles("users.csv");
  103. std::vector<std::string> userList;
  104. std::vector<std::string> productList;
  105. userList.reserve(USERS);
  106. productList.reserve(PRODUCTS);
  107. for(int i = 0; i < USERS; ++i){
  108. std::string id = uuid();
  109. std::string name = randomName();
  110. userList.push_back(id);
  111. friendFiles << id << "," << name << "\n";
  112. }
  113. friendFiles.close();
  114.  
  115. std::ofstream productFiles("products.csv");
  116. for(int i = 0; i < PRODUCTS; ++i){
  117. std::string id = uuid();
  118. std::string name = randomProduct();
  119. productList.push_back(id);
  120. productFiles << id << "," << name << "\n";
  121. }
  122. productFiles.close();
  123.  
  124.  
  125. std::ofstream friendsFile("friends.csv");
  126. for(const std::string &id : userList){
  127. for(int i = 0; i < 1 + std::rand() % FRIENDS_BY_USER; ++i){
  128. std::string friendWith = randomElement(userList);
  129. if(id == friendWith) continue;
  130. friendsFile << id << "," << friendWith << "\n";
  131. }
  132. }
  133. friendsFile.close();
  134.  
  135. std::ofstream productBuy("buy.csv");
  136. for(const std::string &id : userList){
  137. for(int i = 0; i < 1 + std::rand() % PRODUCTS_BY_USER; ++i){
  138. std::string buying = randomElement(productList);
  139. productBuy << id << "," << buying << "\n";
  140. }
  141. }
  142. productBuy.close();
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement