|
|
|
@ -2,12 +2,20 @@
|
|
|
|
|
#include <rng.h>
|
|
|
|
|
#include <range.h>
|
|
|
|
|
|
|
|
|
|
constexpr const static util::range<f64> SAMPLE_RANGE { 0.0, 1.0 };
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static inline constexpr T _scale(f64 sample, T max)
|
|
|
|
|
{
|
|
|
|
|
return (T)(sample * (f64)max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static inline constexpr T _scale(f64 sample, T min, T max)
|
|
|
|
|
{
|
|
|
|
|
return SAMPLE_RANGE.scale<T>({ min, max }, sample);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Random::next_bool() { return sample() < 0.5; }
|
|
|
|
|
#define NEXT(T) T Random::next_ ## T(T max) { return _scale<T >(sample(), max); }
|
|
|
|
|
#define NEXTT(n) NEXT(i ## n) NEXT(u ## n)
|
|
|
|
@ -47,13 +55,14 @@ N_INTS
|
|
|
|
|
|
|
|
|
|
#undef NEXTT
|
|
|
|
|
#undef NEXT
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
|
|
//TODO: next_*(min, max)
|
|
|
|
|
//next_*(min, max)
|
|
|
|
|
#define NEXT(T) T Random::next_ ## T(T min, T max) { return _scale(sample(), min, max); }
|
|
|
|
|
#define NEXTT(n) NEXT(i ## n) NEXT(u ## n)
|
|
|
|
|
|
|
|
|
|
void __()
|
|
|
|
|
{
|
|
|
|
|
util::range<int> test(-10, 20);
|
|
|
|
|
util::range<long> test2(-1000, 2000);
|
|
|
|
|
test.scale(test2, 5);
|
|
|
|
|
N_INTS
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#undef NEXTT
|
|
|
|
|
#undef NEXT
|
|
|
|
|
// ---
|
|
|
|
|