diff options
Diffstat (limited to 'normal_distribution.cpp')
| -rw-r--r-- | normal_distribution.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/normal_distribution.cpp b/normal_distribution.cpp index c9cf701..fd52ac1 100644 --- a/normal_distribution.cpp +++ b/normal_distribution.cpp @@ -1,6 +1,11 @@ #include <algorithm> #include <cstdio> #include <random> +#include <set> +#include <vector> + +constexpr size_t length = 1048576; + int main() { std::random_device randomDevice; @@ -8,9 +13,21 @@ int main() { std::normal_distribution<long double> normalDistribution(2147483647, 2147483647); - for (int i = 0; i < 1048576; i++) { - printf("%llu\n", - (unsigned long long)std::round(normalDistribution(randomEngine))); + std::set<long long> set; + + std::vector<long long> vector; + + vector.reserve(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); + } + + for (long long element : vector) { + printf("%lld\n", element); } return 0; |
