|
|
@ -1,6 +1,7 @@
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
|
|
#include <rng/impl.hpp>
|
|
|
|
#include <rng/impl.hpp>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline unsigned char RNG::byte()
|
|
|
|
inline unsigned char RNG::byte()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -45,3 +46,47 @@ std::int64_t RNG::next_long()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (chance() ? 1l : -1l) * (std::int64_t)floor(sample() * (double)INT64_MAX);
|
|
|
|
return (chance() ? 1l : -1l) * (std::int64_t)floor(sample() * (double)INT64_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <rng.h>
|
|
|
|
|
|
|
|
#include <panic.h>
|
|
|
|
|
|
|
|
namespace { // C interface
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#define extract_ptr(ptr) ((RNG*)(ptr))
|
|
|
|
|
|
|
|
static inline RNG& extract_ref(rng_t rng)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return *extract_ptr(rng);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
|
|
static inline T* extract_downcast_ptr(rng_t rng)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return dynamic_cast<T*>(extract_ptr(rng));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rng_t rng_new(rng_init_opt opt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(opt.kind)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case RNG_KIND_FRNG: return (rng_t) new rng::frng(opt.init.frng.state);
|
|
|
|
|
|
|
|
case RNG_KIND_DRNG: return (rng_t) new rng::drng(opt.init.drng.state);
|
|
|
|
|
|
|
|
case RNG_KIND_XORNG: return (rng_t) new rng::xoroshiro128plus(opt.init.xorng.state);
|
|
|
|
|
|
|
|
default: panic("Unknown RNG init opt: %d", opt.kind);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void rng_free(rng_t rng)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RNG* ptr = (RNG*)rng;
|
|
|
|
|
|
|
|
delete ptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void rng_test_spec(rng_t rng)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << "rng_test_spec:" << endl;
|
|
|
|
|
|
|
|
rng::test_algo(std::move(extract_ref(rng)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|