You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

#pragma once
#include <rngxx.hpp>
#include "internal/mem.h"
#include "internal/common.h"
namespace rng
{
struct crand final : public Random
{
// This range is inclusive
constexpr static inline i64 RANGE_MIN = - (1L << 31);
constexpr static inline i64 RANGE_MAX = (1L << 31) - 1;
crand();
crand(u64 seed);
inline ~crand() override{}
RNG_OVERRIDE(inline i64, next_i64, ()) { return _sample_int(); }
RNG_OVERRIDE(u64, next_u64,());
RNG_OVERRIDE(i32, next_i32,());
RNG_OVERRIDE(u32, next_u32,());
RNG_OVERRIDE(void, next_bytes, (u8* p, usize n));
protected:
inline constexpr i64 _max_i64() const override { return RANGE_MAX; }
inline constexpr u64 _max_u64() const override { return (u64)RANGE_MAX; }
// the rest of the base `_max_*` functions are valid, as they will always be equal to or less than INT32_MAX (the upper bound of dr48.)
f64 _sample() override;
void next_v64(u64* p, usize n) override;
void next_v32(u32* p, usize n) override;
private:
struct _opaque;
struct _deleter { static void delete_object(_opaque** st); };
mem::aligned_ptr<_opaque, _deleter> _state;
explicit crand(_opaque* raw);
i64 _sample_int();
};
}