#include #include #include #include #include #include #include #include inline void store_into_vector(unsigned long long value, unsigned long long &max_value, unsigned long long &min_value, std::vector &population_vector) { if (max_value < value) { max_value = value; } if (min_value > value) { min_value = value; } population_vector.push_back(value); } void checkFileValid(const std::string &name, size_t length) { std::vector vector; unsigned long long max_value = 0, min_value = 0xfffffffffffff; FILE *file = fopen(name.c_str(), "r"); assert(file); for (long long i; fscanf(file, "%lld ", &i) != EOF; store_into_vector(i, max_value, min_value, vector)) ; ; fclose(file); vector.resize(length); for (auto element : vector) { assert(element != max_value); assert(element != min_value); } } void progress_bar(const std::set &v, size_t length) { constexpr auto sleep_time = std::chrono::seconds(1); size_t previous_rate = 0; while (v.size() < length) { fprintf(stderr, "\rProgress %.02f%%(%lu) rate: %lu/s", (double)v.size() * 100 / (double)length, v.size(), v.size() - previous_rate); previous_rate = v.size(); std::this_thread::sleep_for(sleep_time); } fputs("", stderr); } int main(int argc, char const *argv[]) { if (argc == 3) { checkFileValid(argv[1], std::stol(argv[2])); return 0; } std::random_device randomDevice; std::mt19937 randomEngine(randomDevice()); std::normal_distribution normalDistribution(2147483648, 2147483648); size_t length; if (argc == 1) { length = 1048576; } else { try { length = std::strtol(argv[1], nullptr, 10); } catch (...) { fprintf(stderr, "Wrong arguments\n"); return 1; } } std::set set; std::vector vector; vector.reserve(length); std::thread progress_tl(progress_bar, std::ref(set), length); while (set.size() != length) { auto element = (long long)std::round(normalDistribution(randomEngine)); auto ret = set.insert(element); if (ret.second) { vector.push_back(element); } } progress_tl.join(); assert(vector.size() == length); auto offset = *set.begin() < 0 ? 0 - *set.begin() : 0; for (auto element : vector) { printf("%lld\n", element + offset); } return 0; }