From 85296957a8d755cda80c5dc00dcef4555ff14ebc Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Mon, 20 Jun 2022 16:15:34 +0800 Subject: fix(script): Fix normal distribution generator * feat(script): Add p.d.f. and c.d.f. painter Signed-off-by: KunoiSayami --- normal_distribution.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'normal_distribution.cpp') 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 #include #include +#include +#include + +constexpr size_t length = 1048576; + int main() { std::random_device randomDevice; @@ -8,9 +13,21 @@ int main() { std::normal_distribution normalDistribution(2147483647, 2147483647); - for (int i = 0; i < 1048576; i++) { - printf("%llu\n", - (unsigned long long)std::round(normalDistribution(randomEngine))); + std::set set; + + std::vector 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; -- cgit v1.3.1