summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rwxr-xr-xex_normal_distribution.py24
-rw-r--r--normal_distribution.cpp23
3 files changed, 48 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 0d51e4e..5fbfc08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,7 @@ CTestTestfile.cmake
_deps
cmake-*/
.idea/
-test \ No newline at end of file
+test
+
+*.txt
+!CMakeLists.txt \ No newline at end of file
diff --git a/ex_normal_distribution.py b/ex_normal_distribution.py
new file mode 100755
index 0000000..f82df93
--- /dev/null
+++ b/ex_normal_distribution.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+import matplotlib.pyplot as plt
+
+
+def function_pdf(element: list[int]):
+ plt.hist(element, bins=500)
+ plt.show()
+
+
+def function_cdf(element: list[int]):
+ plt.hist(element, bins=500, cumulative=True)
+ plt.show()
+
+
+def normal_distribution():
+ with open('normal_distribution.txt') as fin:
+ context = fin.read()
+ elements = list(map(int, context.splitlines()))
+ function_pdf(elements)
+ function_cdf(elements)
+
+
+if __name__ == '__main__':
+ normal_distribution()
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;