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.

44 lines
1.1 KiB

#pragma once
#include "../common.h"
#include <rng.h>
#include "../mem.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{}
inline i64 next_i64() override { return _sample_int(); }
u64 next_u64() override;
i32 next_i32() override;
u32 next_u32() override;
void next_bytes(u8* p, usize n) override;
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();
};
}