Index: trunk/src/core/random.cc
===================================================================
--- trunk/src/core/random.cc	(revision 319)
+++ trunk/src/core/random.cc	(revision 372)
@@ -7,15 +7,17 @@
 #include "nv/core/random.hh"
 #include "nv/core/time.hh"
+#include <random>
 
 using namespace nv;
 
 random::random( random::seed_type seed /*= 0 */ )
-	: rng( seed == 0 ? randomized_seed() : seed )
-{
-	
+{
+	static_assert( sizeof( std::mt19937 ) < sizeof( random::m_data ), "No room for mersenne twister!" );
+	new (m_data)std::mt19937( seed == 0 ? randomized_seed() : seed );
 }
 
 random::seed_type random::randomize()
 {
+	std::mt19937& rng = *(( std::mt19937* )m_data);
 	seed_type seed = randomized_seed();
 	rng.seed( seed );
@@ -25,4 +27,5 @@
 void random::set_seed( random::seed_type seed /*= 0 */ )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	rng.seed( seed == 0 ? randomized_seed() : seed );
 }
@@ -36,4 +39,5 @@
 random::result_type random::rand()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	return rng();
 }
@@ -41,4 +45,5 @@
 sint32 random::srand( sint32 val )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_int_distribution<sint32> dist( 0, val - 1 );
 	return dist( rng );
@@ -47,4 +52,5 @@
 uint32 random::urand( uint32 val )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_int_distribution<uint32> dist( 0, val - 1 );
 	return dist( rng );
@@ -53,4 +59,5 @@
 f32 random::frand( f32 val )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist( 0, val );
 	return dist( rng );
@@ -59,4 +66,5 @@
 sint32 random::srange( sint32 min, sint32 max )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_int_distribution<sint32> dist( min, max );
 	return dist( rng );
@@ -65,4 +73,5 @@
 uint32 random::urange( uint32 min, uint32 max )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_int_distribution<uint32> dist( min, max );
 	return dist( rng );
@@ -71,4 +80,5 @@
 f32 random::frange( f32 min, f32 max )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist( min, max );
 	return dist( rng );
@@ -77,4 +87,5 @@
 uint32 random::dice( uint32 count, uint32 sides )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_int_distribution<uint32> dist( 1, sides );
 	uint32 result = 0;
@@ -88,4 +99,6 @@
 random::seed_type random::randomized_seed()
 {
+	// TODO: this seems off, as it might often seed the same, use general time 
+	// instead
 	return narrow_cast< seed_type >( get_ticks() );
 }
@@ -93,4 +106,5 @@
 nv::vec2 nv::random::precise_unit_vec2()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist( 0, glm::pi<float>() * 2.f );
 	float angle = dist( rng );
@@ -100,4 +114,5 @@
 nv::vec3 nv::random::precise_unit_vec3()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
 	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
@@ -114,4 +129,5 @@
 nv::vec2 nv::random::fast_disk_point()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist( 0.0f, 1.0f );
 	float r1 = dist( rng );
@@ -124,4 +140,5 @@
 nv::vec2 nv::random::precise_disk_point()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> unit( 0.0f, 1.0f );
 	std::uniform_real_distribution<f32> angle( 0.0f, glm::pi<float>() );
@@ -133,4 +150,5 @@
 nv::vec3 nv::random::fast_sphere_point()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f );
 	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
@@ -150,4 +168,5 @@
 nv::vec3 nv::random::precise_sphere_point()
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f );
 	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
@@ -166,4 +185,5 @@
 nv::vec2 nv::random::precise_ellipse_point( const vec2& radii )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> distx( -radii.x, radii.x );
 	std::uniform_real_distribution<f32> disty( -radii.y, radii.y );
@@ -184,4 +204,5 @@
 nv::vec3 nv::random::precise_ellipsoid_point( const vec3& radii )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	std::uniform_real_distribution<f32> distx( -radii.x, radii.x );
 	std::uniform_real_distribution<f32> disty( -radii.y, radii.y );
@@ -204,4 +225,5 @@
 nv::vec2 nv::random::fast_hollow_disk_point( float iradius, float oradius )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	float idist2 = iradius * iradius;
 	float odist2 = oradius * oradius;
@@ -217,4 +239,5 @@
 nv::vec3 nv::random::fast_hollow_sphere_point( float iradius, float oradius )
 {
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
 	float idist3 = iradius * iradius * iradius;
 	float odist3 = oradius * oradius * oradius;
@@ -231,5 +254,6 @@
 nv::vec2 nv::random::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
 {
-	vec2 iradii2    = iradii * iradii;
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
+	vec2 iradii2 = iradii * iradii;
 	vec2 opoint     = ellipse_edge( oradii );
 	vec2 opoint2    = opoint * opoint;
@@ -251,5 +275,6 @@
 nv::vec3 nv::random::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
 {
-	vec3 iradii2    = iradii * iradii;
+	std::mt19937& rng = *( ( std::mt19937* )m_data );
+	vec3 iradii2 = iradii * iradii;
 	vec3 opoint     = ellipsoid_edge( oradii );
 	vec3 opoint2    = opoint * opoint;
