74 template <
typename T> T
rand(T a, T b) {
75 return a+T(
rand01()*(b-a));
84 template <
typename T>
void shuffle(std::vector<T>& a) {
85 for (
size_t i=0;i<a.size();++i) {
87 std::swap(a[i], a[r]);
93 std::random_device rd;
97 std::uniform_real_distribution<float> dis01;
99 std::uniform_real_distribution<float> dis11;
101 std::uniform_real_distribution<float> disPi;
103 std::uniform_real_distribution<float> dis005;
105 std::uniform_real_distribution<float> dis051;
Random staticRand
Global PRNG instance for convenience functions.
Definition Rand.cpp:52
void shuffle(std::vector< T > &a)
Shuffle a container in-place using Fisher–Yates.
Definition Rand.h:84
float rand005()
Draw a random float in [0, 0.5).
Definition Rand.cpp:36
float rand01()
Draw a random float in [0, 1).
Definition Rand.cpp:32
float rand051()
Draw a random float in [0.5, 1).
Definition Rand.cpp:40
float rand11()
Draw a random float in [-1, 1).
Definition Rand.cpp:44
T rand(T a, T b)
Draw a value uniformly in the half-open interval [a, b).
Definition Rand.h:74
Random()
Construct and seed from std::random_device.
Definition Rand.cpp:7
float rand0Pi()
Draw a random float in [0, ).
Definition Rand.cpp:48