diff --git a/NEWS b/NEWS
index 9bedf67100278d593138e397ba04886fba5c6e0d..413759954b349040f071c20bf73c8a0d3a94ee5b 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ Bugfixes
 - lua resolve(): correctly include EDNS0 in the virtual packet (!963)
   Custom modules might have been confused by that.
 - do not leak bogus data into SERVFAIL answers (#396)
+- improve random Lua number generator initialization (!979)
 
 Incompatible changes
 --------------------
diff --git a/daemon/engine.c b/daemon/engine.c
index 3dd9faeb2b2de8b5d92f5552afb2869cf1fd3fba..0c34c4b2fb371e14555fddcb208a21c4b4420395 100644
--- a/daemon/engine.c
+++ b/daemon/engine.c
@@ -500,6 +500,13 @@ static int init_state(struct engine *engine)
 	lua_setglobal(engine->L, "map");
 	lua_pushlightuserdata(engine->L, engine);
 	lua_setglobal(engine->L, "__engine");
+	/* Random number generator */
+	lua_getfield(engine->L, LUA_GLOBALSINDEX, "math");
+	lua_getfield(engine->L, -1, "randomseed");
+	lua_remove(engine->L, -2);
+	lua_Number seed = kr_rand_bytes(sizeof(lua_Number));
+	lua_pushnumber(engine->L, seed);
+	lua_call(engine->L, 1, 0);
 	return kr_ok();
 }
 
diff --git a/modules/prefill/prefill.lua b/modules/prefill/prefill.lua
index d0f2d194f92f2015055ccd7fcf05b1453b2adaae..d8f4adf5be26baab8286eccdfbb249be719bf0c7 100644
--- a/modules/prefill/prefill.lua
+++ b/modules/prefill/prefill.lua
@@ -142,10 +142,6 @@ function forward_references.fill_cache()
 	restart_timer(rz_cur_interval)
 end
 
-function prefill.init()
-	math.randomseed(os.time())
-end
-
 function prefill.deinit()
 	stop_timer()
 end