1 #ifndef INCLUDE_AL_STD_RANDOM_HPP
2 #define INCLUDE_AL_STD_RANDOM_HPP
14 unsigned int al_random_seed();
24 std::uniform_int_distribution<int> distribution;
28 void seed(
unsigned int seed);
30 int operator()(
int b);
31 int operator()(
int a,
int b);
40 std::uniform_real_distribution<float> distribution;
44 void seed(
unsigned int seed);
46 float operator()(
float b);
47 float operator()(
float a,
float b);
56 std::poisson_distribution<int> distribution;
60 void seed(
unsigned int seed);
62 int operator()(
float m);
71 std::exponential_distribution<float> distribution;
75 void seed(
unsigned int seed);
77 float operator()(
float r);
86 std::normal_distribution<float> distribution;
90 void seed(
unsigned int seed);
92 float operator()(
float mean,
float stdev);
103 inline int uniformi(
int high) {
return global_ui()(high); }
106 inline int uniformi(
int low,
int high) {
108 return global_ui()(high, low);
110 return global_ui()(low, high);
120 return global()(0.0f, float(hi));
127 return global()(float(hi), float(lo));
129 return global()(float(lo), float(hi));
139 return global()(float(-lim), float(lim));
147 template <
int N,
class T>
152 for (
int i = 0; i < N; ++i) {
161 template <
template <
int,
class>
class VecType,
int N,
class T>
162 inline void ball(VecType<N, T>& point) {
167 template <
class VecType>
175 inline float normal() {
return global_normal()(); }
188 inline float sign(
float x = 1.f) {
189 static float arr[2] = {-1.0f, 1.0f};
190 return x * arr[global_ui()(0, 1)];
T mean(const T &v1, const T &v2)
bool prob()
Returns true with probability 0.5.
float normal()
Returns standard normal variate.
float uniformS()
Returns signed uniform random in (-1, 1)
float triangle()
Returns triangle distribution variate, in (-1,1)
rand_uniformf & global()
Get global random number generator.
float sign(float x=1.f)
Returns argument with sign randomly flipped.
float uniform()
Returns uniform random in [0, 1)
void ball(T *point)
Returns point within a unit ball.