diff --git a/src/lol/math/rand.h b/src/lol/math/rand.h index 3938904c..e60d0812 100644 --- a/src/lol/math/rand.h +++ b/src/lol/math/rand.h @@ -33,14 +33,29 @@ template static inline T rand(T a) return rand() % a; } -template<> -inline half rand(half a) { return a * std::rand() / RAND_MAX; } -template<> -inline float rand(float a) { return a * std::rand() / RAND_MAX; } -template<> -inline double rand(double a) { return a * std::rand() / RAND_MAX; } -template<> -inline ldouble rand(ldouble a) { return a * std::rand() / RAND_MAX; } +template<> inline half rand(half a) +{ + float f = (float)std::rand() / (float)RAND_MAX; + return (half)(a * f); +} + +template<> inline float rand(float a) +{ + float f = (float)std::rand() / (float)RAND_MAX; + return a * f; +} + +template<> inline double rand(double a) +{ + double f = (double)std::rand() / (double)RAND_MAX; + return a * f; +} + +template<> inline ldouble rand(ldouble a) +{ + ldouble f = (ldouble)std::rand() / (ldouble)RAND_MAX; + return a * f; +} /* Two-value random number generator -- no need for specialisation */ template static inline T rand(T a, T b)