Index: trunk/src/lua/lua_aux.cc
===================================================================
--- trunk/src/lua/lua_aux.cc	(revision 179)
+++ trunk/src/lua/lua_aux.cc	(revision 180)
@@ -7,5 +7,7 @@
 #include "nv/lua/lua_aux.hh"
 
+#include <utility>
 #include "nv/lua/lua_raw.hh"
+#include "nv/random.hh"
 
 static int nluaaux_table_copy( lua_State* L )
@@ -87,7 +89,50 @@
 }
 
+static int nluaaux_math_dieroll( lua_State* L )
+{
+	int dice  = luaL_checkinteger( L,  1 );
+	int sides = luaL_checkinteger( L,  2 );
+	if ( dice < 1 )  luaL_argerror( L, 1, "die count lower than 1!" );
+	if ( sides < 1 ) luaL_argerror( L, 2, "side count lower than 1!" );
+	lua_pushnumber( L, nv::random::get().dice( dice, sides ) );
+	return 1;
+}
+
+static int nluaaux_math_random( lua_State* L )
+{
+	if ( lua_gettop( L ) == 0 )
+	{
+		lua_pushnumber( L, nv::random::get().frand(1.0f) );
+	}
+	else
+	{
+		if ( lua_gettop( L ) == 1 )
+		{
+			int arg1 = luaL_checkinteger( L, 1 );
+			if ( arg1 < 1 ) arg1 = 1;
+			lua_pushunsigned( L, nv::random::get().urange( 1, arg1 ) );
+		}
+		else
+		{
+			int arg1 = luaL_checkinteger( L, 1 );
+			int arg2 = luaL_checkinteger( L, 2 );
+			if (arg2 < arg1) std::swap( arg2, arg1 );
+			lua_pushinteger( L, nv::random::get().srange( arg1, arg2 ) );
+		}
+	}
+	return 1;
+}
+
+static int nluaaux_math_randomseed( lua_State* L )
+{
+	nv::random::get().set_seed( static_cast< nv::uint32 > ( L, 1 ) );
+	return 0;
+}
 
 static const struct luaL_Reg nluaaux_math_aux_f [] = {
 	{ "clamp",     nluaaux_math_clamp },
+	{ "random",    nluaaux_math_random },
+	{ "randomseed",nluaaux_math_randomseed },
+	{ "dieroll",   nluaaux_math_dieroll },
 	{ NULL, NULL }
 };
