|
|
@ -26,15 +26,14 @@ namespace rng
|
|
|
|
crand::crand(u64 seed) : crand(reinterpret_cast<_opaque*>(_jr_new(seed))){}
|
|
|
|
crand::crand(u64 seed) : crand(reinterpret_cast<_opaque*>(_jr_new(seed))){}
|
|
|
|
crand::crand() : crand(0xabad1dea){}
|
|
|
|
crand::crand() : crand(0xabad1dea){}
|
|
|
|
|
|
|
|
|
|
|
|
i64 crand::_sample_raw() { return _jr_proc(reinterpret_cast<jr_state*>(_state.get_ptr())); }
|
|
|
|
i64 crand::_sample_int() { return _jr_proc(reinterpret_cast<jr_state*>(_state.get_ptr())); } //RANGE_MIN..=RANGE_MAX
|
|
|
|
|
|
|
|
f64 crand::_sample() { return _jr_procf(reinterpret_cast<jr_state*>(_state.get_ptr())); } //0..1
|
|
|
|
//TODO: properly implemet this f64 crand::_sample() { return (f64)std::bit_cast<u64>(_sample_raw()) / (f64)UINT64_MAX; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Overrides //
|
|
|
|
// Overrides //
|
|
|
|
u64 crand::next_u64() { return std::bit_cast<u64>(std::abs(_sample_raw()) & INT32_MAX); } // remove sign bit because it messes with the range.
|
|
|
|
u64 crand::next_u64() { return std::bit_cast<u64>(std::abs(_sample_int()) & INT32_MAX); }
|
|
|
|
|
|
|
|
// next_i/u64(max) overrides not nessicary, the impl would be same as base. same with array next_*(p, n) overrides
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Implementing next_i64(i64 max) should be trivial. the man page for drand48 shows its output range, just map that range to `0..=max`
|
|
|
|
//TODO: next_bytes(), next_v*()
|
|
|
|
//TODO: make the default range for all non-bounded `next_i/u*` the same range as drand48's. If that's too big for the integer type, scale it down.
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void rng_test()
|
|
|
|
void rng_test()
|
|
|
|