|
|
|
@ -30,7 +30,7 @@ namespace rng
|
|
|
|
|
{
|
|
|
|
|
void crand::_deleter::delete_object(_opaque** state) { _jr_free(reinterpret_cast<jr_state*>(*state)); *state = nullptr; }
|
|
|
|
|
|
|
|
|
|
crand::crand(_opaque* raw) :_state(mem::aligned_ptr<_opaque, _deleter>(raw)){}
|
|
|
|
|
crand::crand(_opaque* raw) : Random(), _state(mem::aligned_ptr<_opaque, _deleter>(raw)){}
|
|
|
|
|
|
|
|
|
|
crand::crand(u64 seed) : crand(reinterpret_cast<_opaque*>(_jr_new(seed))){}
|
|
|
|
|
crand::crand() : crand(0xabad1dea){}
|
|
|
|
@ -65,28 +65,8 @@ namespace rng
|
|
|
|
|
}
|
|
|
|
|
void crand::next_v64(u64* p, usize n)
|
|
|
|
|
{
|
|
|
|
|
while( n --> 0) *p++ = u64(_sample_int() & INT32_MAX) + (u64(_sample_int() & INT32_MAX) << 32);
|
|
|
|
|
while( n --> 0 ) *p++ = u64(_sample_int() & INT32_MAX) + (u64(_sample_int() & INT32_MAX) << 32);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rng_test()
|
|
|
|
|
{
|
|
|
|
|
rng::crand _r(123);
|
|
|
|
|
Random& r = _r;
|
|
|
|
|
printf("%lu %lu %lu\n", r.next_u64(), r.next_u64(), r.next_u64());
|
|
|
|
|
printf("%d %d %d\n", r.next_i32(), r.next_i32(), r.next_i32());
|
|
|
|
|
printf("%u %u %u\n", r.next_u32(), r.next_u32(), r.next_u32());
|
|
|
|
|
|
|
|
|
|
union {
|
|
|
|
|
volatile u64 u;
|
|
|
|
|
u8 b[sizeof(u64)];
|
|
|
|
|
std::array<u8, sizeof(u64)> a;
|
|
|
|
|
} thing = {0};
|
|
|
|
|
|
|
|
|
|
r.next_bytes(thing.b, sizeof(u64));
|
|
|
|
|
printf("chaos: %lu, %lu, %lu\n", thing.u, (r.next_bytes(thing.a), thing.u), (r.next_bytes(thing.b), thing.u));
|
|
|
|
|
|
|
|
|
|
// TODO: these aren't implemented yet in the base Random huh...
|
|
|
|
|
printf("---\n%u %d %d %u\n", r.next_u32(10, 20), r.next_i32(10, 20), r.next_i32(10), r.next_u32(10));
|
|
|
|
|
}
|
|
|
|
|