Created
May 19, 2024 15:40
-
-
Save Injazz/c2ab5bc0de9c32074b5fa4328a4f32ab to your computer and use it in GitHub Desktop.
Generates json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <vector> | |
#include <fstream> | |
#include <random> | |
using namespace std; | |
int generate_a_random_number(mt19937 rng, int init_num, int last_num) | |
{ | |
uniform_int_distribution<int> d(init_num,last_num); | |
return d(rng); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
string probel = " "; | |
string tire = "-"; | |
string dvoet = ": "; | |
string tab = " "; | |
string modelA[] = { "Horizon", "Mega", "Rushing", "Stylish", "PRO-MX", "Hyper", "Fast", "Furious", "Cool", "Fantastic", "Never-Ending", "Inevitable", "Instant", "Durable", "Mysterious", "Special", "Secret", "Amazing", "Absolute", "OMEGA" }; | |
string modelB[] = { "Rush", "Dawn", "Race", "Turbo", "Speed", "Bike", "Thug", "Dragon", "Tiger", "Wind", "Evil", "Mutant", "Bro", "Bicycle", "Rage", "Delivery", "Duck", "Goose", "Transport", "Power" }; | |
string modelC[] = { "RX", "TR", "BB", "R", "GRA", "SDI", "DR", "B", "RED", "LO", "A", "B", "C", "D", "E", "F", "S", "SR", "SSR", "UR" }; | |
int number_of_items = 64; | |
string filename = "database"; | |
string directory = argv[0]; | |
directory.erase(directory.find_last_of('\\')+1); | |
if (argc > 2) | |
{ | |
filename = (string)argv[1]; | |
number_of_items = (uintptr_t)argv[2]; | |
} | |
filename = directory + filename + ".json"; | |
ofstream output(filename, ios::trunc); | |
seed_seq seq{time(0)}; | |
vector<std::uint32_t> seeds(number_of_items*20); | |
seq.generate(seeds.begin(), seeds.end()); | |
output << "{\n" + tab; | |
output << "\"items\": [\n"; | |
for(int i = 0; i < number_of_items; i++) | |
{ | |
output << tab + tab + "{\n"; | |
output << tab + tab + tab; | |
output << "\"id\": "; | |
output << to_string(i) << ",\n"; | |
int a = seeds[i] % 20; | |
int b = seeds[i+1] % 20; | |
int c = seeds[i+2] % 20; | |
output << tab + tab + tab; | |
output << "\"model\": \""; | |
int d = seeds[i+3] % 99; | |
output << modelA[a] + probel + modelB[b] + probel + modelC[c] + to_string(d); | |
output << "\",\n"; | |
int typ = seeds[i+4] % 5; | |
output << tab + tab + tab; | |
output << "\"ttype\": "; | |
output << to_string(typ) << ",\n"; | |
int wheeln = seeds[i+5] % 4 + 1; | |
output << tab + tab + tab; | |
output << "\"number_of_wheels\": "; | |
output << to_string(wheeln) << ",\n"; | |
int wheels = seeds[i+6] % 20 + 1; | |
output << tab + tab + tab; | |
output << "\"wheel_size\": "; | |
output << to_string(wheels) << ",\n"; | |
int seatn = 1; | |
if (typ == 3) | |
{ | |
seatn = seeds[i+7] % 5 + 1; | |
} else if (typ == 4) | |
{ | |
seatn = 0; | |
} | |
output << tab + tab + tab; | |
output << "\"number_of_seats\": "; | |
output << to_string(seatn) << ",\n"; | |
int price = (seeds[i+8] % 20 + 1) * 50; | |
output << tab + tab + tab; | |
output << "\"price_to_rent\": "; | |
output << to_string(price) << ",\n"; | |
int is_rent = seeds[i+9] % 2; | |
string is_rented = is_rent == 0 ? "false" : "true"; | |
output << tab + tab + tab; | |
output << "\"is_rented\": "; | |
output << is_rented << "\n"; | |
output << tab + tab << "}"; | |
if (i != number_of_items-1) { | |
output << ","; | |
} | |
output << "\n"; | |
} | |
output << tab << "]\n}"; | |
output.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment