summaryrefslogtreecommitdiff
path: root/core/test_rng.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/test_rng.cpp')
-rw-r--r--core/test_rng.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/core/test_rng.cpp b/core/test_rng.cpp
new file mode 100644
index 0000000..4ee419c
--- /dev/null
+++ b/core/test_rng.cpp
@@ -0,0 +1,76 @@
+#include <assert.h>
+#include <iostream>
+
+#include "rng.hpp"
+
+using namespace RNG;
+//using namespace std;
+
+int main() {
+ seed_t src(0),
+ s( split(src)),
+ s1(split(next(src)));
+
+ std::cout << "RNG size: " << sizeof(generator) << std::endl;
+ // for (int j=0; j<10; j++) {
+ // s = j;
+ // for (int i=0; i<10; i++) {
+ // std::cout << s << ", ";
+ // s = next(s);
+ // }
+ // std::cout << std::endl;
+ // }
+
+ // determinism?
+ assert(next(s).rng == next(s).rng);
+
+ // respect seed
+ assert(next(s).rng != next(s1).rng);
+
+ // respect equipropable distribution
+ {
+ const int times(1000);
+ double mean(0);
+ for (int i=0; i<times; i++) {
+ double res = equi(s);
+ // std::cout << res << std::endl;
+
+ s = next(s);
+ assert(0 <= res);
+ assert(res < 1);
+ mean += res;
+ }
+ mean /= times;
+ assert(0.45 < mean && mean < 0.55);
+ }
+
+ // respect exponential distribution
+ {
+ const int times(1000);
+ double mean(0);
+ for (int i=0; i<times; i++) {
+ double res = expo(s, 66);
+ // std::cout << res << " " << s.rng << std::endl;
+ s = next(s);
+ assert(0 <= res);
+ mean += res;
+ }
+ mean /= times;
+ assert(60 < mean && mean < 75);
+ }
+
+ // print 1000 parallel streams
+ // for (int i=0; i<1000; i++) {
+ // seed_t s = split(src);
+ // src = next(src, 40);
+
+ // double d = 0;
+ // while (d < 100) {
+ // std::cerr << d << "\t" << i << std::endl;
+ // d += expo(s, 1.0);
+ // s = next(s);
+ // }
+ // }
+
+ return 0;
+}
contact: Jan Huwald // Impressum