Index: code/trunk/src/libraries/util/Math.h
===================================================================
--- code/trunk/src/libraries/util/Math.h	(revision 11052)
+++ code/trunk/src/libraries/util/Math.h	(revision 11071)
@@ -46,4 +46,6 @@
 #include <cmath>
 #include <cstdlib>
+#include <random>
+#include <type_traits>
 
 #include <OgreMath.h>
@@ -73,11 +75,11 @@
     namespace math
     {
-        const float twoPi   = 6.283185482025146484375f;     ///< PI * 2
-        const float pi      = 3.1415927410125732421875f;    ///< PI
-        const float pi_2    = 1.57079637050628662109375f;   ///< PI / 2
-        const float pi_4    = 0.785398185253143310546875f;  ///< PI / 4
-        const float e       = 2.718281269073486328125f;     ///< e
-        const float sqrt2   = 1.41421353816986083984375f;   ///< sqrt(2)
-        const float sqrt2_2 = 0.707106769084930419921875f;  ///< sqrt(2) / 2
+        constexpr float twoPi   = 6.283185482025146484375f;     ///< PI * 2
+        constexpr float pi      = 3.1415927410125732421875f;    ///< PI
+        constexpr float pi_2    = 1.57079637050628662109375f;   ///< PI / 2
+        constexpr float pi_4    = 0.785398185253143310546875f;  ///< PI / 4
+        constexpr float e       = 2.718281269073486328125f;     ///< e
+        constexpr float sqrt2   = 1.41421353816986083984375f;   ///< sqrt(2)
+        constexpr float sqrt2_2 = 0.707106769084930419921875f;  ///< sqrt(2) / 2
     }
 
@@ -104,5 +106,5 @@
     */
     template <typename T>
-    inline T sgn(T x)
+    constexpr inline T sgn(T x)
     {
         return (x >= 0) ? (T)1 : (T)-1;
@@ -116,13 +118,7 @@
     */
     template <typename T>
-    inline T clamp(T x, T min, T max)
-    {
-        if (x < min)
-            return min;
-
-        if (x > max)
-            return max;
-
-        return x;
+    constexpr inline T clamp(T x, T min, T max)
+    {
+        return x < min ? min : (x > max ? max : x);
     }
 
@@ -131,5 +127,5 @@
     */
     template <typename T>
-    inline T square(T x)
+    constexpr inline T square(T x)
     {
         return x*x;
@@ -140,5 +136,5 @@
     */
     template <typename T>
-    inline T cube(T x)
+    constexpr inline T cube(T x)
     {
         return x*x*x;
@@ -183,11 +179,15 @@
         @c Vector3 you get <tt>Vector3(0, 0, 0)</tt>.
     */
-    template <typename T>
-    inline T zeroise()
-    {
-        // Default, raise a compiler error without including large boost header cascade.
-        T temp();
-        *********temp; // If you reach this code, you abused zeroise()!
-        return temp;
+    template <typename T> /* for normal classes */ typename std::enable_if<!std::is_enum<T>::value, T>::type
+    inline /*T*/ zeroise()
+    {
+        // If you reach this code, you abused zeroise()!
+        static_assert(sizeof(T) != sizeof(T), "No template specialization available for T");
+    }
+    /// Implementation for enum classes: uses the underlying type to create a zero value.
+    template <typename T> /* for enum classes */ typename std::enable_if<std::is_enum<T>::value, T>::type
+    inline /*T*/ zeroise()
+    {
+        return static_cast<T>(zeroise<typename std::underlying_type<T>::type>());
     }
 
@@ -206,5 +206,5 @@
     template <> inline long double          zeroise<long double>()          { return 0; }
     template <> inline bool                 zeroise<bool>()                 { return 0; }
-    template <> inline void*                zeroise<void*>()                { return 0; }
+    template <> inline void*                zeroise<void*>()                { return nullptr; }
     template <> inline std::string          zeroise<std::string>()          { return std::string(); }
     template <> inline orxonox::Radian      zeroise<orxonox::Radian>()      { return orxonox::Radian(0.0f); }
@@ -258,4 +258,31 @@
     }
 
+    namespace detail
+    {
+        /**
+        Random number generator used for the functions below. Marked extern to only have one global instance.
+        */
+        _UtilExport extern std::mt19937 rngen;
+    }
+
+    /**
+    @brief Seeds the random number generator used for the functions below.
+    */
+    inline void rndseed(unsigned int seed)
+    {
+        detail::rngen.seed(seed);
+    }
+
+    /**
+    @brief Returns a random number between @a min and almost @a max: <tt>min <= rnd < max</tt>.
+    @param min The minimum
+    @param max The maximum
+    */
+    inline float rnd(float min, float max)
+    {
+        std::uniform_real_distribution<float> dist(min, max);
+        return dist(detail::rngen);
+    }
+
     /**
         @brief Returns a random number between 0 and almost 1: <tt>0 <= rnd < 1</tt>.
@@ -263,5 +290,5 @@
     inline float rnd()
     {
-        return rand() / (RAND_MAX + 1.0f);
+        return rnd(0, 1);
     }
 
@@ -272,15 +299,5 @@
     inline float rnd(float max)
     {
-        return rnd() * max;
-    }
-
-    /**
-        @brief Returns a random number between @a min and almost @a max: <tt>min <= rnd < max</tt>.
-        @param min The minimum
-        @param max The maximum
-    */
-    inline float rnd(float min, float max)
-    {
-        return rnd(max - min) + min;
+        return rnd(0, max);
     }
 
@@ -290,5 +307,6 @@
     inline float rndsgn()
     {
-        return static_cast<float>((rand() & 0x2) - 1); // rand() & 0x2 is either 2 or 0
+        std::uniform_int_distribution<> dist;
+        return static_cast<float>((dist(detail::rngen) & 0x2) - 1); // dist(...) & 0x2 is either 2 or 0
     }
 
