diff --git a/src/lua_baselib.c b/src/lua_baselib.c
index 525f2fe68481271d2573eee8e6039c7f37c0cabc..20342d33e6ed548b438069aa9a7e5c92f5956d9e 100644
--- a/src/lua_baselib.c
+++ b/src/lua_baselib.c
@@ -115,6 +115,8 @@ static int lib_pRandomKey(lua_State *L)
 	INT32 a = (INT32)luaL_checkinteger(L, 1);
 
 	NOHUD
+	if (a > 65536)
+		LUA_UsageWarning(L, "P_RandomKey: range > 65536 is undefined behavior");
 	lua_pushinteger(L, P_RandomKey(a));
 	return 1;
 }
@@ -130,6 +132,8 @@ static int lib_pRandomRange(lua_State *L)
 		a = b;
 		b = c;
 	}
+	if ((b-a+1) > 65536)
+		LUA_UsageWarning(L, "P_RandomRange: range > 65536 is undefined behavior");
 	lua_pushinteger(L, P_RandomRange(a, b));
 	return 1;
 }
diff --git a/src/lua_script.h b/src/lua_script.h
index 45fab2f53570f4118fdb14026807532b59dc9080..447d3d686a2f104d3a42b486fc1d2f41f66ea3f6 100644
--- a/src/lua_script.h
+++ b/src/lua_script.h
@@ -81,4 +81,15 @@ void COM_Lua_f(void);
 	}\
 }
 
+// Warnings about incorrect function usage.
+// Shows once, then never again, like deprecation
+#define LUA_UsageWarning(L, warningmsg)\
+{\
+	static UINT8 seen = 0;\
+	if (!seen) {\
+		seen = 1;\
+		CONS_Alert(CONS_WARNING,"%s\n", warningmsg);\
+	}\
+}
+
 #endif