1#ifndef AARAND_AARAND_HPP
2#define AARAND_AARAND_HPP
31template<
typename T =
double,
class Engine>
33 typedef typename Engine::result_type R;
34 static_assert(std::numeric_limits<R>::is_integer,
"RNG engine must yield integer results");
38 static_assert(!std::numeric_limits<R>::is_signed,
"RNG engine must yield unsigned integers");
46 constexpr T factor = ONE_ / (
static_cast<T
>(Engine::max() - Engine::min()) + ONE_);
52 result =
static_cast<T
>(eng() - Engine::min()) * factor;
53 }
while (result == ONE_);
68template<
typename T =
double,
class Engine>
70 constexpr T PI_ = 3.14159265358979323846;
89template<
typename T =
double,
class Engine>
94 }
while (
val ==
static_cast<T>(0));
95 return -std::log(
val);
108template<
typename T =
int,
class Engine>
110 static_assert(std::numeric_limits<T>::is_integer);
112 throw std::runtime_error(
"'bound' should be a positive integer");
115 typedef typename Engine::result_type
R;
116 static_assert(std::numeric_limits<R>::is_integer);
117 static_assert(!std::numeric_limits<R>::is_signed);
119 constexpr R range = Engine::max() - Engine::min();
121 throw std::runtime_error(
"'bound' should be less than the RNG range");
162template<
class In,
class Engine>
166 for (
size_t i = 0;
i <
n - 1; ++
i) {
188template<
class In,
class Out,
class Engine>
191 const double threshold =
static_cast<double>(
s)/(
n -
i);
213template<
class Out,
class Engine>
215 for (
size_t i = 0;
i <
bound &&
s; ++
i) {
Namespace containing Aaron's random distribution functions.
T standard_exponential(Engine &eng)
Definition aarand.hpp:90
std::pair< T, T > standard_normal(Engine &eng)
Definition aarand.hpp:69
void shuffle(In values, size_t n, Engine &eng)
Definition aarand.hpp:163
T standard_uniform(Engine &eng)
Definition aarand.hpp:32
void sample(In values, size_t n, size_t s, Out output, Engine &eng)
Definition aarand.hpp:189
T discrete_uniform(Engine &eng, T bound)
Definition aarand.hpp:109