From 315295bbf1c53c71035669749e86baf40291a87d Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 25 Nov 2020 20:59:32 +0000 Subject: [PATCH] rng impls --- lean/include/rng.h | 11 ++++++++ lean/include/rng/{drng.h => drng.hpp} | 0 lean/src/main.c | 7 ++--- lean/src/rng/drng.cpp | 2 +- lean/src/rng/test.cpp | 37 +++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) rename lean/include/rng/{drng.h => drng.hpp} (100%) create mode 100644 lean/src/rng/test.cpp diff --git a/lean/include/rng.h b/lean/include/rng.h index 57852a7..cf5135d 100644 --- a/lean/include/rng.h +++ b/lean/include/rng.h @@ -9,12 +9,23 @@ extern "C" { void frng_test(); void xorng_test(); void drng_test(); + +void rng_test(); + #ifdef __cplusplus } // RNG interfaces #include +#include #include +namespace rng { + void test_algo(RNG&& rng); + +template::value>::value __fuck> + inline void test_algo(R&& rng) { test_algo(static_cast(rng)); } +} #endif #endif /* _RNG_H */ diff --git a/lean/include/rng/drng.h b/lean/include/rng/drng.hpp similarity index 100% rename from lean/include/rng/drng.h rename to lean/include/rng/drng.hpp diff --git a/lean/src/main.c b/lean/src/main.c index 255cc61..71356a3 100644 --- a/lean/src/main.c +++ b/lean/src/main.c @@ -43,9 +43,10 @@ int main(int argc, char** argv) { struct prog_args args = {.argc = argc, .argv = argv}; - frng_test(); - xorng_test(); - drng_test(); + rng_test(); + //frng_test(); + //xorng_test(); + //drng_test(); if( argv[1] ) { map_and_then(argv[1], &map_callback, &args); diff --git a/lean/src/rng/drng.cpp b/lean/src/rng/drng.cpp index 40e7934..b85ea34 100644 --- a/lean/src/rng/drng.cpp +++ b/lean/src/rng/drng.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include namespace rng { diff --git a/lean/src/rng/test.cpp b/lean/src/rng/test.cpp new file mode 100644 index 0000000..dd7b5e2 --- /dev/null +++ b/lean/src/rng/test.cpp @@ -0,0 +1,37 @@ +#include +#include + +namespace rng { + void test_algo(RNG&& rng) + { + using namespace std; + + for(int i=0;i<10;i++) { + double d = rng.next_double(); + long l = rng.next_long(-10, 10); + + std::array ar; + for(auto& i : ar) i = rng.chance(); + + cout << "\t(Sampled: " << d; + cout << ", Long: " << l; + cout << ", Bools: [ "; + for(const auto& i : ar) cout << i << " "; + cout << "])" << endl; + } + } +} + +extern "C" void rng_test() +{ + using namespace std; + + cout << "frng:" << endl; + rng::test_algo(rng::frng(1.0, 1.2)); + + cout << "drng:" << endl; + rng::test_algo(rng::drng(10)); + + cout << "xoroshiro128+" << endl; + rng::test_algo(rng::xoroshiro128plus(100ul, 200ul)); +}