Index: trunk/nv/random.hh
===================================================================
--- trunk/nv/random.hh	(revision 175)
+++ trunk/nv/random.hh	(revision 175)
@@ -0,0 +1,88 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_RANDOM_HH
+#define NV_RANDOM_HH
+
+#include <random>
+#include <nv/common.hh>
+#include <nv/math.hh>
+
+namespace nv
+{
+
+	class random
+	{
+	public:
+		typedef std::mt19937::result_type result_type;
+		typedef std::mt19937::result_type seed_type;
+
+		random( seed_type seed = 0 );
+		seed_type randomize();
+		void set_seed( seed_type seed = 0 );
+		static random& get();
+		result_type rand();
+		sint32 srand( sint32 val );
+		uint32 urand( uint32 val );
+		f32 frand( f32 val );
+		sint32 srange( sint32 min, sint32 max );
+		uint32 urange( uint32 min, uint32 max );
+		f32 frange( f32 min, f32 max );
+		uint32 dice( uint32 count, uint32 sides );
+
+		template < typename T >
+		glm::detail::tvec2<T> range( glm::detail::tvec2<T> min, glm::detail::tvec2<T> max )
+		{
+			return glm::detail::tvec2<T>( 
+				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
+				range_impl( min.y, max.y, std::is_floating_point<T>() )
+				);
+		}
+
+		template < typename T >
+		glm::detail::tvec3<T> range( glm::detail::tvec3<T> min, glm::detail::tvec3<T> max )
+		{
+			return glm::detail::tvec3<T>( 
+				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
+				range_impl( min.y, max.y, std::is_floating_point<T>() ),
+				range_impl( min.z, max.z, std::is_floating_point<T>() )
+				);
+		}
+
+		template < typename T >
+		glm::detail::tvec4<T> range( glm::detail::tvec4<T> min, glm::detail::tvec4<T> max )
+		{
+			return glm::detail::tvec4<T>( 
+				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
+				range_impl( min.y, max.y, std::is_floating_point<T>() ),
+				range_impl( min.z, max.z, std::is_floating_point<T>() ), 
+				range_impl( min.w, max.w, std::is_floating_point<T>() ) 
+				);
+		}
+
+	private:
+		static seed_type randomized_seed();
+
+		template <typename T>
+		T range_impl( T min, T max, const std::true_type& )
+		{
+			std::uniform_real_distribution<T> dist( min, max );
+			return dist( rng );
+		}
+
+		template <typename T>
+		T range_impl( T min, T max, const std::false_type& )
+		{
+			std::uniform_int_distribution<T> dist( min, max );
+			return dist( rng );
+		}
+	private:
+		std::mt19937 rng;
+	};
+
+}
+
+#endif // NV_RANDOM_HH
Index: trunk/src/random.cc
===================================================================
--- trunk/src/random.cc	(revision 175)
+++ trunk/src/random.cc	(revision 175)
@@ -0,0 +1,91 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/random.hh"
+#include "nv/time.hh"
+
+using namespace nv;
+
+random::random( random::seed_type seed /*= 0 */ )
+	: rng( seed == 0 ? randomized_seed() : seed )
+{
+	
+}
+
+random::seed_type random::randomize()
+{
+	seed_type seed = randomized_seed();
+	rng.seed( seed );
+	return seed;
+}
+
+void random::set_seed( random::seed_type seed /*= 0 */ )
+{
+	rng.seed( seed == 0 ? randomized_seed() : seed );
+}
+
+random& random::get()
+{
+	static random default_rng;
+	return default_rng;
+}
+
+random::result_type random::rand()
+{
+	return rng();
+}
+
+sint32 random::srand( sint32 val )
+{
+	std::uniform_int_distribution<sint32> dist( 0, val - 1 );
+	return dist( rng );
+}
+
+uint32 random::urand( uint32 val )
+{
+	std::uniform_int_distribution<sint32> dist( 0, val - 1 );
+	return dist( rng );
+}
+
+f32 random::frand( f32 val )
+{
+	std::uniform_real_distribution<f32> dist( 0, val );
+	return dist( rng );
+}
+
+sint32 random::srange( sint32 min, sint32 max )
+{
+	std::uniform_int_distribution<sint32> dist( min, max );
+	return dist( rng );
+}
+
+uint32 random::urange( uint32 min, uint32 max )
+{
+	std::uniform_int_distribution<sint32> dist( min, max );
+	return dist( rng );
+}
+
+f32 random::frange( f32 min, f32 max )
+{
+	std::uniform_real_distribution<f32> dist( min, max );
+	return dist( rng );
+}
+
+uint32 random::dice( uint32 count, uint32 sides )
+{
+	std::uniform_int_distribution<uint32> dist( 1, sides );
+	uint32 result = 0;
+	while (count-- > 0)
+	{
+		result += dist( rng );
+	};
+	return result;
+}
+
+random::seed_type random::randomized_seed()
+{
+	return narrow_cast< seed_type >( get_ticks() );
+}
